mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-21 07:56:16 -04:00
Client side / server side require
This commit is contained in:
parent
261bbd460f
commit
2a58a62dcc
7 changed files with 59 additions and 9 deletions
|
@ -10,17 +10,20 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
res.end();
|
||||
});
|
||||
|
||||
args.app.get('/static/plugins/*', function(req, res) {
|
||||
var url = req.url.replace(/\.\./g, '').split("?")[0];
|
||||
url = url.split("/");
|
||||
url.splice(0, 3);
|
||||
var plugin_name = url.splice(0, 1)[0];
|
||||
url = url.join("/");
|
||||
/* 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", url));
|
||||
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]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue