mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-22 16:36:15 -04:00
Fixing client side require, the minify code is completly unused now, very ugly solution
This commit is contained in:
parent
8b5925440a
commit
7b518eeb2d
4 changed files with 249 additions and 786 deletions
|
@ -1,15 +1,60 @@
|
|||
var path = require('path');
|
||||
var minify = require('../../utils/Minify');
|
||||
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugins");
|
||||
var CachingMiddleware = require('../../utils/caching_middleware');
|
||||
var settings = require("../../utils/Settings");
|
||||
var Yajsml = require('yajsml');
|
||||
var fs = require("fs");
|
||||
var ERR = require("async-stacktrace");
|
||||
|
||||
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()); // + "\n require.setLibraryURI('/plugins'); ");
|
||||
res.end();
|
||||
/* 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(/^\/minified\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) {
|
||||
var plugin_name = req.params[0];
|
||||
var modulePath = req.url.split("?")[0].substr("/minified/plugins/".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('/(minified|static)/*', assetCache.handle);
|
||||
|
||||
// Minify will serve static files compressed (minify enabled). It also has
|
||||
// file-specific hacks for ace/require-kernel/etc.
|
||||
args.app.all('/static/:filename(*)', minify.minify);
|
||||
|
||||
// Setup middleware that will package JavaScript files served by minify for
|
||||
// CommonJS loader on the client-side.
|
||||
var jsServer = new (Yajsml.Server)({
|
||||
rootPath: 'minified/'
|
||||
, rootURI: 'http://localhost:' + settings.port + '/static/js/'
|
||||
});
|
||||
|
||||
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
||||
var associations =
|
||||
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
||||
var associator = new StaticAssociator(associations);
|
||||
jsServer.setAssociator(associator);
|
||||
args.app.use(jsServer);
|
||||
|
||||
// serve plugin definitions
|
||||
// not very static, but served here so that client can do require("pluginfw/static/js/plugin-definitions.js");
|
||||
args.app.get('/pluginfw/plugin-definitions.json', function (req, res, next) {
|
||||
|
@ -17,30 +62,4 @@ exports.expressCreateServer = function (hook_name, args, cb) {
|
|||
res.write(JSON.stringify({"plugins": plugins.plugins, "parts": plugins.parts}));
|
||||
res.end();
|
||||
});
|
||||
|
||||
|
||||
/* 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(/^\/plugins\/([^\/]+)\/static\/(.*)/, function(req, res, next) {
|
||||
var plugin_name = req.params[0];
|
||||
var url = req.params[1].replace(/\.\./g, '').split("?")[0];
|
||||
|
||||
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 });
|
||||
});
|
||||
|
||||
// Handle normal static files
|
||||
args.app.get('/static/*', function(req, res) {
|
||||
var filePath = path.normalize(__dirname + "/../../.." +
|
||||
req.url.replace(/\.\./g, '').split("?")[0]);
|
||||
res.sendfile(filePath, { maxAge: exports.maxAge });
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue