2012-02-24 20:45:02 +01:00
|
|
|
var path = require('path');
|
2012-02-25 17:23:44 +01:00
|
|
|
var minify = require('../../utils/Minify');
|
2012-02-25 19:43:00 +01:00
|
|
|
var plugins = require("../../pluginfw/plugins");
|
2012-02-24 20:45:02 +01:00
|
|
|
|
2012-02-25 16:53:15 +01:00
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
2012-02-24 20:45:02 +01:00
|
|
|
//serve static files
|
|
|
|
args.app.get('/static/js/require-kernel.js', function (req, res, next) {
|
|
|
|
res.header("Content-Type","application/javascript; charset: utf-8");
|
2012-02-26 15:34:03 +01:00
|
|
|
res.write(minify.requireDefinition() + "\n require.setLibraryURI('/plugins'); ");
|
2012-02-24 20:45:02 +01:00
|
|
|
res.end();
|
|
|
|
});
|
2012-02-25 19:43:00 +01:00
|
|
|
|
2012-02-26 15:34:03 +01:00
|
|
|
/* 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,
|
2012-02-26 13:54:32 +01:00
|
|
|
commonly ETHERPAD_ROOT/node_modules/ep_myplugin/static/js/test.js
|
2012-02-26 00:45:06 +01:00
|
|
|
*/
|
2012-02-26 15:34:03 +01:00
|
|
|
args.app.get(/^\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) {
|
|
|
|
var plugin_name = req.params[0];
|
|
|
|
var url = req.params[1].replace(/\.\./g, '').split("?")[0];
|
2012-02-25 19:43:00 +01:00
|
|
|
|
2012-02-26 15:34:03 +01:00
|
|
|
if (plugins.plugins[plugin_name] == undefined) {
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
|
|
|
|
var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", url));
|
2012-02-25 19:43:00 +01:00
|
|
|
res.sendfile(filePath, { maxAge: exports.maxAge });
|
|
|
|
});
|
|
|
|
|
2012-02-26 00:45:06 +01:00
|
|
|
// Handle normal static files
|
2012-02-25 19:43:00 +01:00
|
|
|
args.app.get('/static/*', function(req, res) {
|
2012-02-25 17:23:44 +01:00
|
|
|
var filePath = path.normalize(__dirname + "/../../.." +
|
2012-02-24 20:45:02 +01:00
|
|
|
req.url.replace(/\.\./g, '').split("?")[0]);
|
|
|
|
res.sendfile(filePath, { maxAge: exports.maxAge });
|
|
|
|
});
|
|
|
|
}
|