require(ep_pluginname/static/blabla); now works both on client and server
parent
ac7ad6b519
commit
fd5b7c1080
|
@ -1,4 +1,4 @@
|
|||
test = ep_client_require("/plugins/ep_fintest/test.js");
|
||||
test = require("ep_fintest/static/js/test.js");
|
||||
console.log("FOOO:", test.foo);
|
||||
|
||||
exports.somehook = function (hook_name, args, cb) {
|
||||
|
|
|
@ -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 });
|
||||
});
|
||||
|
||||
|
|
|
@ -27,7 +27,6 @@ var db = require('./db/DB');
|
|||
var async = require('async');
|
||||
var express = require('express');
|
||||
var path = require('path');
|
||||
require("./pluginfw/require"); // Load globals
|
||||
var plugins = require("./pluginfw/plugins");
|
||||
var hooks = require("./pluginfw/hooks");
|
||||
var npm = require("npm/lib/npm.js");
|
||||
|
|
Loading…
Reference in New Issue