2012-02-25 17:23:44 +01:00
|
|
|
var minify = require('../../utils/Minify');
|
2020-09-06 15:27:18 -04:00
|
|
|
var plugins = require("ep_etherpad-lite/static/js/pluginfw/plugin_defs");
|
2012-03-04 23:45:33 +01:00
|
|
|
var CachingMiddleware = require('../../utils/caching_middleware');
|
|
|
|
var settings = require("../../utils/Settings");
|
2015-01-18 20:15:17 +00:00
|
|
|
var Yajsml = require('etherpad-yajsml');
|
2012-04-04 15:10:27 +02:00
|
|
|
var _ = require("underscore");
|
2012-02-24 20:45:02 +01:00
|
|
|
|
2012-02-25 16:53:15 +01:00
|
|
|
exports.expressCreateServer = function (hook_name, args, cb) {
|
2012-07-22 23:54:38 -07:00
|
|
|
|
2012-03-04 23:45:33 +01:00
|
|
|
// Cache both minified and static.
|
|
|
|
var assetCache = new CachingMiddleware;
|
2015-04-11 09:54:40 -05:00
|
|
|
args.app.all(/\/javascripts\/(.*)/, assetCache.handle);
|
2012-03-04 23:45:33 +01:00
|
|
|
|
|
|
|
// Minify will serve static files compressed (minify enabled). It also has
|
|
|
|
// file-specific hacks for ace/require-kernel/etc.
|
2015-04-10 05:52:58 -05:00
|
|
|
args.app.all('/static/:filename(*)', minify.minify);
|
2012-03-04 23:45:33 +01:00
|
|
|
|
|
|
|
// Setup middleware that will package JavaScript files served by minify for
|
|
|
|
// CommonJS loader on the client-side.
|
Fix misparse of port when binding Unix socket
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.
2018-07-28 04:38:17 -04:00
|
|
|
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
|
2012-03-04 23:45:33 +01:00
|
|
|
var jsServer = new (Yajsml.Server)({
|
2012-03-10 14:13:08 -08:00
|
|
|
rootPath: 'javascripts/src/'
|
Fix misparse of port when binding Unix socket
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.
2018-07-28 04:38:17 -04:00
|
|
|
, rootURI: 'http://invalid.invalid/static/js/'
|
2012-03-10 14:03:29 -08:00
|
|
|
, libraryPath: 'javascripts/lib/'
|
Fix misparse of port when binding Unix socket
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.
2018-07-28 04:38:17 -04:00
|
|
|
, libraryURI: 'http://invalid.invalid/static/plugins/'
|
2012-09-03 14:37:10 -07:00
|
|
|
, requestURIs: minify.requestURIs // Loop-back is causing problems, this is a workaround.
|
2012-02-25 19:43:00 +01:00
|
|
|
});
|
|
|
|
|
2012-03-04 23:45:33 +01:00
|
|
|
var StaticAssociator = Yajsml.associators.StaticAssociator;
|
|
|
|
var associations =
|
|
|
|
Yajsml.associators.associationsForSimpleMapping(minify.tar);
|
|
|
|
var associator = new StaticAssociator(associations);
|
|
|
|
jsServer.setAssociator(associator);
|
2015-04-07 07:55:05 -05:00
|
|
|
|
|
|
|
args.app.use(jsServer.handle.bind(jsServer));
|
2012-03-04 23:45:33 +01:00
|
|
|
|
|
|
|
// 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) {
|
2012-04-04 15:10:27 +02:00
|
|
|
|
|
|
|
var clientParts = _(plugins.parts)
|
|
|
|
.filter(function(part){ return _(part).has('client_hooks') });
|
2019-04-16 00:34:29 +02:00
|
|
|
|
2012-04-04 15:10:27 +02:00
|
|
|
var clientPlugins = {};
|
2019-04-16 00:34:29 +02:00
|
|
|
|
2012-04-04 15:10:27 +02:00
|
|
|
_(clientParts).chain()
|
|
|
|
.map(function(part){ return part.plugin })
|
|
|
|
.uniq()
|
|
|
|
.each(function(name){
|
|
|
|
clientPlugins[name] = _(plugins.plugins[name]).clone();
|
|
|
|
delete clientPlugins[name]['package'];
|
|
|
|
});
|
2019-04-16 00:34:29 +02:00
|
|
|
|
2012-03-24 13:28:17 +01:00
|
|
|
res.header("Content-Type","application/json; charset=utf-8");
|
2012-04-04 15:10:27 +02:00
|
|
|
res.write(JSON.stringify({"plugins": clientPlugins, "parts": clientParts}));
|
2012-03-04 23:45:33 +01:00
|
|
|
res.end();
|
2012-02-24 20:45:02 +01:00
|
|
|
});
|
|
|
|
}
|