mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-04-20 15:36:16 -04:00

The hostname:port of URIs used in Minify are currently bogus and refer to localhost only for historical reasons; there's no reason to retain them and omitting them avoids generating an invalid URI when "port" is not an integer. Context: settings.port is passed to express's listen; if not numeric, it is used a filename for a Unix domain socket. This allows e.g. starting a server to be reverse-proxied on a multi-user system, using the filesystem to handle access control and avoiding need to allocate port numbers. Before this change, etherpad-lite starts without error when configured to listen on a Unix domain socket in this manner. However, `pad.js` and `ace2_common.js` are generated incorrecting, causing an error "Uncaught Error: The module at "ep_etherpad-lite/static/js/rjquery" does not exist." when loading the editor: When settings.port is a non-numeric string, e.g. `etherpad.sock`, a URI of the form `http://localhost:etherpad.sock/static/js/rjquery.js` is generated and parsed to find the file needed. In this case, the file searched for is `:etherpad.sock/static/js/rjquery.js`, rather than the expected `static/js/rjquery.js`. No such file exists, and the required code is silently omitted from the bundle. As a workaround, hard-code a (meaningless) hostname which can be parsed correctly, since the current code makes no use of it anyway.
58 lines
2.2 KiB
JavaScript
58 lines
2.2 KiB
JavaScript
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('etherpad-yajsml');
|
|
var _ = require("underscore");
|
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
|
|
|
// Cache both minified and static.
|
|
var assetCache = new CachingMiddleware;
|
|
args.app.all(/\/javascripts\/(.*)/, 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.
|
|
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
|
|
var jsServer = new (Yajsml.Server)({
|
|
rootPath: 'javascripts/src/'
|
|
, rootURI: 'http://invalid.invalid/static/js/'
|
|
, libraryPath: 'javascripts/lib/'
|
|
, libraryURI: 'http://invalid.invalid/static/plugins/'
|
|
, requestURIs: minify.requestURIs // Loop-back is causing problems, this is a workaround.
|
|
});
|
|
|
|
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
|
var associations =
|
|
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
|
var associator = new StaticAssociator(associations);
|
|
jsServer.setAssociator(associator);
|
|
|
|
args.app.use(jsServer.handle.bind(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) {
|
|
|
|
var clientParts = _(plugins.parts)
|
|
.filter(function(part){ return _(part).has('client_hooks') });
|
|
|
|
var clientPlugins = {};
|
|
|
|
_(clientParts).chain()
|
|
.map(function(part){ return part.plugin })
|
|
.uniq()
|
|
.each(function(name){
|
|
clientPlugins[name] = _(plugins.plugins[name]).clone();
|
|
delete clientPlugins[name]['package'];
|
|
});
|
|
|
|
res.header("Content-Type","application/json; charset=utf-8");
|
|
res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts}));
|
|
res.end();
|
|
});
|
|
}
|