summaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorChad Weider <cweider@oofn.net>2012-03-10 14:03:29 -0800
committerChad Weider <cweider@oofn.net>2012-03-10 14:39:37 -0800
commit0d6ec8c04ab3bef7edc4d9e7292b112208db1e8d (patch)
tree35684a249ed7e0219a092f87d469952a58da889e /src/node
parent1a1f222221266a20ce1adcf839c581e664f88283 (diff)
downloadetherpad-lite-0d6ec8c04ab3bef7edc4d9e7292b112208db1e8d.zip
Minify implements virtual plugins resources.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/hooks/express/static.js27
-rw-r--r--src/node/utils/Minify.js17
2 files changed, 19 insertions, 25 deletions
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;
diff --git a/src/node/utils/Minify.js b/src/node/utils/Minify.js
index a49195a7..4e1c44db 100644
--- a/src/node/utils/Minify.js
+++ b/src/node/utils/Minify.js
@@ -27,6 +27,7 @@ var cleanCSS = require('clean-css');
var jsp = require("uglify-js").parser;
var pro = require("uglify-js").uglify;
var path = require('path');
+var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
var RequireKernel = require('require-kernel');
var server = require('../server');
@@ -63,6 +64,22 @@ exports.minify = function(req, res, next)
return;
}
+ /* Handle static files for plugins:
+ paths like "plugins/ep_myplugin/static/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
+ */
+ var match = filename.match(/^plugins\/([^\/]+)\/static\/(.*)/);
+ if (match) {
+ var pluginName = match[1];
+ var resourcePath = match[2];
+ var plugin = plugins.plugins[pluginName];
+ if (plugin) {
+ var pluginPath = plugin.package.realPath;
+ filename = path.relative(ROOT_DIR, pluginPath + '/static/' + resourcePath);
+ }
+ }
+
// What content type should this be?
// TODO: This should use a MIME module.
var contentType;