pad.libre-service.eu-etherpad/src/node/hooks/express/static.js

33 lines
1.3 KiB
JavaScript
Raw Normal View History

var path = require('path');
var minify = require('../../utils/Minify');
2012-02-25 19:43:00 +01:00
var plugins = require("../../pluginfw/plugins");
2012-02-25 16:53:15 +01:00
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();
});
2012-02-25 19:43:00 +01:00
2012-02-26 00:45:06 +01:00
/* 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];
2012-02-25 19:43:00 +01:00
2012-02-26 00:45:06 +01:00
var filePath = path.normalize(path.join(plugins.plugins[plugin_name].package.path, "static", type_dir, 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) {
var filePath = path.normalize(__dirname + "/../../.." +
req.url.replace(/\.\./g, '').split("?")[0]);
res.sendfile(filePath, { maxAge: exports.maxAge });
});
}