From 1239ce7f284821ad4ce51f8219c480ff557a5b86 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sun, 26 Feb 2012 13:07:51 +0100 Subject: The Big Renaming - etherpad is now an NPM module --- src/node/hooks/express/static.js | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/node/hooks/express/static.js (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js new file mode 100644 index 00000000..a160423d --- /dev/null +++ b/src/node/hooks/express/static.js @@ -0,0 +1,32 @@ +var path = require('path'); +var minify = require('../../utils/Minify'); +var plugins = require("../../pluginfw/plugins"); + +exports.expressCreateServer = function (hook_name, args, cb) { + //serve static files + args.app.get('/static/js/require-kernel.js', function (req, res, next) { + res.header("Content-Type","application/javascript; charset: utf-8"); + res.write(minify.requireDefinition()); + res.end(); + }); + + /* Handle paths like "/static/js/plugins/pluginomatic_myplugin/test.js" + by rewriting it to ROOT_PATH_OF_MYPLUGIN/static/js/test.js, + commonly ETHERPAD_ROOT/node_modules/pluginomatic_myplugin/static/js/test.js + */ + args.app.get(/^\/static\/([^\/]+)\/plugins\/([^\/]+)\/(.*)/, function(req, res) { + var type_dir = req.params[0].replace(/\.\./g, '').split("?")[0]; + var plugin_name = req.params[1]; + var url = req.params[2].replace(/\.\./g, '').split("?")[0]; + + var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", type_dir, url)); + res.sendfile(filePath, { maxAge: exports.maxAge }); + }); + + // Handle normal static files + args.app.get('/static/*', function(req, res) { + var filePath = path.normalize(__dirname + "/../../.." + + req.url.replace(/\.\./g, '').split("?")[0]); + res.sendfile(filePath, { maxAge: exports.maxAge }); + }); +} -- cgit v1.2.3 From da52353ba3777ff8573db8f92e362863e146a88e Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sun, 26 Feb 2012 13:54:32 +0100 Subject: The big rename of pluginbs from pluginomatic to ep --- src/node/hooks/express/static.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index a160423d..eb7f03a9 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -10,9 +10,9 @@ exports.expressCreateServer = function (hook_name, args, cb) { res.end(); }); - /* Handle paths like "/static/js/plugins/pluginomatic_myplugin/test.js" + /* Handle paths like "/static/js/plugins/ep_myplugin/test.js" by rewriting it to ROOT_PATH_OF_MYPLUGIN/static/js/test.js, - commonly ETHERPAD_ROOT/node_modules/pluginomatic_myplugin/static/js/test.js + commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js */ args.app.get(/^\/static\/([^\/]+)\/plugins\/([^\/]+)\/(.*)/, function(req, res) { var type_dir = req.params[0].replace(/\.\./g, '').split("?")[0]; -- cgit v1.2.3 From fd5b7c1080d605caba658c0c4913e298ef0184c2 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sun, 26 Feb 2012 15:34:03 +0100 Subject: require(ep_pluginname/static/blabla); now works both on client and server --- src/node/hooks/express/static.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index eb7f03a9..567b4d7d 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -6,20 +6,24 @@ exports.expressCreateServer = function (hook_name, args, cb) { //serve static files args.app.get('/static/js/require-kernel.js', function (req, res, next) { res.header("Content-Type","application/javascript; charset: utf-8"); - res.write(minify.requireDefinition()); + res.write(minify.requireDefinition() + "\n require.setLibraryURI('/plugins'); "); res.end(); }); - /* Handle paths like "/static/js/plugins/ep_myplugin/test.js" - by rewriting it to ROOT_PATH_OF_MYPLUGIN/static/js/test.js, + /* Handle static files for plugins: + paths like "/static/plugins/ep_myplugin/js/test.js" + are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js */ - args.app.get(/^\/static\/([^\/]+)\/plugins\/([^\/]+)\/(.*)/, function(req, res) { - var type_dir = req.params[0].replace(/\.\./g, '').split("?")[0]; - var plugin_name = req.params[1]; - var url = req.params[2].replace(/\.\./g, '').split("?")[0]; + args.app.get(/^\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) { + var plugin_name = req.params[0]; + var url = req.params[1].replace(/\.\./g, '').split("?")[0]; - var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", type_dir, url)); + if (plugins.plugins[plugin_name] == undefined) { + return next(); + } + + var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", url)); res.sendfile(filePath, { maxAge: exports.maxAge }); }); -- cgit v1.2.3 From 2c7b84ca3ef6eac2a0773bedf47f4d69564e7236 Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Sun, 26 Feb 2012 22:01:52 +0100 Subject: Minify now supports plugins --- src/node/hooks/express/static.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 567b4d7d..ade5478a 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -6,7 +6,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { //serve static files args.app.get('/static/js/require-kernel.js', function (req, res, next) { res.header("Content-Type","application/javascript; charset: utf-8"); - res.write(minify.requireDefinition() + "\n require.setLibraryURI('/plugins'); "); + res.write(minify.requireDefinition()); // + "\n require.setLibraryURI('/plugins'); "); res.end(); }); @@ -24,6 +24,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { } var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", url)); + res.sendfile(filePath, { maxAge: exports.maxAge }); }); -- cgit v1.2.3 From 73aa0687b8cd696ded66208f5550d83c2a62739c Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Thu, 1 Mar 2012 18:45:02 +0100 Subject: Client side hooks are now loaded and works --- src/node/hooks/express/static.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index ade5478a..093d0a04 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -10,6 +10,15 @@ exports.expressCreateServer = function (hook_name, args, cb) { res.end(); }); + // serve plugin definitions + // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); + args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) { + res.header("Content-Type","application/json; charset: utf-8"); + res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts})); + res.end(); + }); + + /* Handle static files for plugins: paths like "/static/plugins/ep_myplugin/js/test.js" are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, -- cgit v1.2.3 From 81440cd85605c3e584cba18cf868bab1629c63ba Mon Sep 17 00:00:00 2001 From: Egil Moeller Date: Thu, 1 Mar 2012 19:00:58 +0100 Subject: Removed old pluginfw stuff --- src/node/hooks/express/static.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 093d0a04..461d76af 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -1,6 +1,6 @@ var path = require('path'); var minify = require('../../utils/Minify'); -var plugins = require("../../pluginfw/plugins"); +var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); exports.expressCreateServer = function (hook_name, args, cb) { //serve static files -- cgit v1.2.3 From 7b518eeb2d1e0dbe320fb336ff4156d8aad1514a Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Sun, 4 Mar 2012 23:45:33 +0100 Subject: Fixing client side require, the minify code is completly unused now, very ugly solution --- src/node/hooks/express/static.js | 69 +++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 25 deletions(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 461d76af..9481eb5a 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -1,46 +1,65 @@ var path = require('path'); var minify = require('../../utils/Minify'); var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins"); +var CachingMiddleware = require('../../utils/caching_middleware'); +var settings = require("../../utils/Settings"); +var Yajsml = require('yajsml'); +var fs = require("fs"); +var ERR = require("async-stacktrace"); exports.expressCreateServer = function (hook_name, args, cb) { - //serve static files - args.app.get('/static/js/require-kernel.js', function (req, res, next) { - res.header("Content-Type","application/javascript; charset: utf-8"); - res.write(minify.requireDefinition()); // + "\n require.setLibraryURI('/plugins'); "); - res.end(); - }); - - // serve plugin definitions - // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); - args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) { - res.header("Content-Type","application/json; charset: utf-8"); - res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts})); - res.end(); - }); - - /* Handle static files for plugins: paths like "/static/plugins/ep_myplugin/js/test.js" are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js */ - args.app.get(/^\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) { + args.app.get(/^\/minified\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) { var plugin_name = req.params[0]; - var url = req.params[1].replace(/\.\./g, '').split("?")[0]; + var modulePath = req.url.split("?")[0].substr("/minified/plugins/".length); + var fullPath = require.resolve(modulePath); if (plugins.plugins[plugin_name] == undefined) { return next(); } - var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", url)); + fs.readFile(fullPath, "utf8", function(err, data){ + if(ERR(err)) return; + + res.send("require.define('" + modulePath + "', function (require, exports, module) {" + data + "})"); + }) - res.sendfile(filePath, { maxAge: exports.maxAge }); +//require.define("/plugins.js", function (require, exports, module) { + + //res.sendfile(fullPath); + }); + + // Cache both minified and static. + var assetCache = new CachingMiddleware; + args.app.all('/(minified|static)/*', assetCache.handle); + + // Minify will serve static files compressed (minify enabled). It also has + // file-specific hacks for ace/require-kernel/etc. + args.app.all('/static/:filename(*)', minify.minify); + + // Setup middleware that will package JavaScript files served by minify for + // CommonJS loader on the client-side. + var jsServer = new (Yajsml.Server)({ + rootPath: 'minified/' + , rootURI: 'http://localhost:' + settings.port + '/static/js/' }); - // Handle normal static files - args.app.get('/static/*', function(req, res) { - var filePath = path.normalize(__dirname + "/../../.." + - req.url.replace(/\.\./g, '').split("?")[0]); - res.sendfile(filePath, { maxAge: exports.maxAge }); + var StaticAssociator = Yajsml.associators.StaticAssociator; + var associations = + Yajsml.associators.associationsForSimpleMapping(minify.tar); + var associator = new StaticAssociator(associations); + jsServer.setAssociator(associator); + args.app.use(jsServer); + + // serve plugin definitions + // not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js"); + args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) { + res.header("Content-Type","application/json; charset: utf-8"); + res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts})); + res.end(); }); } -- cgit v1.2.3 From 1a1f222221266a20ce1adcf839c581e664f88283 Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 10 Mar 2012 14:13:08 -0800 Subject: Change paths. --- src/node/hooks/express/static.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 9481eb5a..99701706 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -13,9 +13,9 @@ exports.expressCreateServer = function (hook_name, args, cb) { are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js */ - args.app.get(/^\/minified\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) { + args.app.get(/^\/javascripts\/lib\/([^\/]+)\/static\/(.*)/, function(req, res, next) { var plugin_name = req.params[0]; - var modulePath = req.url.split("?")[0].substr("/minified/plugins/".length); + var modulePath = req.url.split("?")[0].substr("/javascripts/lib/".length); var fullPath = require.resolve(modulePath); if (plugins.plugins[plugin_name] == undefined) { @@ -35,7 +35,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { // Cache both minified and static. var assetCache = new CachingMiddleware; - args.app.all('/(minified|static)/*', assetCache.handle); + args.app.all('/(javascripts|static)/*', assetCache.handle); // Minify will serve static files compressed (minify enabled). It also has // file-specific hacks for ace/require-kernel/etc. @@ -44,7 +44,7 @@ exports.expressCreateServer = function (hook_name, args, cb) { // Setup middleware that will package JavaScript files served by minify for // CommonJS loader on the client-side. var jsServer = new (Yajsml.Server)({ - rootPath: 'minified/' + rootPath: 'javascripts/src/' , rootURI: 'http://localhost:' + settings.port + '/static/js/' }); -- cgit v1.2.3 From 0d6ec8c04ab3bef7edc4d9e7292b112208db1e8d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sat, 10 Mar 2012 14:03:29 -0800 Subject: Minify implements virtual plugins resources. --- src/node/hooks/express/static.js | 27 ++------------------------- 1 file changed, 2 insertions(+), 25 deletions(-) (limited to 'src/node/hooks/express/static.js') diff --git a/src/node/hooks/express/static.js b/src/node/hooks/express/static.js index 99701706..e8f9afbb 100644 --- a/src/node/hooks/express/static.js +++ b/src/node/hooks/express/static.js @@ -8,31 +8,6 @@ var fs = require("fs"); var ERR = require("async-stacktrace"); exports.expressCreateServer = function (hook_name, args, cb) { - /* Handle static files for plugins: - paths like "/static/plugins/ep_myplugin/js/test.js" - are rewritten into ROOT_PATH_OF_MYPLUGIN/static/js/test.js, - commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js - */ - args.app.get(/^\/javascripts\/lib\/([^\/]+)\/static\/(.*)/, function(req, res, next) { - var plugin_name = req.params[0]; - var modulePath = req.url.split("?")[0].substr("/javascripts/lib/".length); - var fullPath = require.resolve(modulePath); - - if (plugins.plugins[plugin_name] == undefined) { - return next(); - } - - fs.readFile(fullPath, "utf8", function(err, data){ - if(ERR(err)) return; - - res.send("require.define('" + modulePath + "', function (require, exports, module) {" + data + "})"); - }) - -//require.define("/plugins.js", function (require, exports, module) { - - //res.sendfile(fullPath); - }); - // Cache both minified and static. var assetCache = new CachingMiddleware; args.app.all('/(javascripts|static)/*', assetCache.handle); @@ -46,6 +21,8 @@ exports.expressCreateServer = function (hook_name, args, cb) { var jsServer = new (Yajsml.Server)({ rootPath: 'javascripts/src/' , rootURI: 'http://localhost:' + settings.port + '/static/js/' + , libraryPath: 'javascripts/lib/' + , libraryURI: 'http://localhost:' + settings.port + '/static/plugins/' }); var StaticAssociator = Yajsml.associators.StaticAssociator; -- cgit v1.2.3