mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
4636833f3d
Summary: This was broken in D11383. Basically, I had the `ws` module installed globally whilst testing, but the changes made do not work if the `ws` module is installed locally (i.e. in the `./support/aphlict/server/node_modules` directory). After poking around, it seems that this is due to the sandboxing that is done by `JX.require`. A quick fix is to just //not// use `JX.require`, although you may have a better idea? The error that is occurring is as follows: ``` <<< UNCAUGHT EXCEPTION! >>> Error: Cannot find module 'ws' at Function.Module._resolveFilename (module.js:338:15) at Function.Module._load (module.js:280:25) at Module.require (module.js:364:17) at require (module.js:380:17) at extra.require (/usr/src/phabricator/webroot/rsrc/externals/javelin/core/init_node.js:48:16) at /usr/src/phabricator/support/aphlict/server/lib/AphlictClientServer.js:10:17 at Script.(anonymous function) [as runInNewContext] (vm.js:41:22) at Object.JX.require (/usr/src/phabricator/webroot/rsrc/externals/javelin/core/init_node.js:58:6) at Object.<anonymous> (/usr/src/phabricator/support/aphlict/server/aphlict_server.js:102:4) at Module._compile (module.js:456:26) >>> Server exited! ``` Test Plan: Now able to start the Aphlict server. Reviewers: joshuaspence Reviewed By: joshuaspence Subscribers: Korvin, epriestley Maniphest Tasks: T6987 Differential Revision: https://secure.phabricator.com/D11425
125 lines
3.1 KiB
JavaScript
125 lines
3.1 KiB
JavaScript
var JX = require('./lib/javelin').JX;
|
|
var http = require('http');
|
|
var https = require('https');
|
|
var util = require('util');
|
|
var fs = require('fs');
|
|
|
|
function parse_command_line_arguments(argv) {
|
|
var config = {
|
|
'client-port': 22280,
|
|
'admin-port': 22281,
|
|
'client-host': '0.0.0.0',
|
|
'admin-host': '127.0.0.1',
|
|
log: '/var/log/aphlict.log',
|
|
'ssl-key': null,
|
|
'ssl-cert': null,
|
|
test: false
|
|
};
|
|
|
|
for (var ii = 2; ii < argv.length; ii++) {
|
|
var arg = argv[ii];
|
|
var matches = arg.match(/^--([^=]+)=(.*)$/);
|
|
if (!matches) {
|
|
throw new Error("Unknown argument '" + arg + "'!");
|
|
}
|
|
if (!(matches[1] in config)) {
|
|
throw new Error("Unknown argument '" + matches[1] + "'!");
|
|
}
|
|
config[matches[1]] = matches[2];
|
|
}
|
|
|
|
config['client-port'] = parseInt(config['client-port'], 10);
|
|
config['admin-port'] = parseInt(config['admin-port'], 10);
|
|
|
|
return config;
|
|
}
|
|
|
|
require('./lib/AphlictLog');
|
|
|
|
var debug = new JX.AphlictLog()
|
|
.addConsole(console);
|
|
|
|
var config = parse_command_line_arguments(process.argv);
|
|
|
|
process.on('uncaughtException', function(err) {
|
|
var context = null;
|
|
if (err.code == 'EACCES' && err.path == config.log) {
|
|
context = util.format(
|
|
'Unable to open logfile ("%s"). Check that permissions are set ' +
|
|
'correctly.',
|
|
err.path);
|
|
}
|
|
|
|
var message = [
|
|
'\n<<< UNCAUGHT EXCEPTION! >>>',
|
|
];
|
|
if (context) {
|
|
message.push(context);
|
|
}
|
|
message.push(err.stack);
|
|
|
|
debug.log(message.join('\n\n'));
|
|
});
|
|
|
|
try {
|
|
require('ws');
|
|
} catch (ex) {
|
|
throw new Error(
|
|
'You need to install the Node.js "ws" module for websocket support. ' +
|
|
'See "Notifications User Guide: Setup and Configuration" in the ' +
|
|
'documentation for instructions. ' + ex.toString());
|
|
}
|
|
|
|
// NOTE: Require these only after checking for the "ws" module, since they
|
|
// depend on it.
|
|
|
|
require('./lib/AphlictAdminServer');
|
|
require('./lib/AphlictClientServer');
|
|
|
|
var ssl_config = {
|
|
enabled: (config['ssl-key'] || config['ssl-cert'])
|
|
};
|
|
|
|
// Load the SSL certificates (if any were provided) now, so that runs with
|
|
// `--test` will see any errors.
|
|
if (ssl_config.enabled) {
|
|
ssl_config.key = fs.readFileSync(config['ssl-key']);
|
|
ssl_config.cert = fs.readFileSync(config['ssl-cert']);
|
|
}
|
|
|
|
// Add the logfile so we'll fail if we can't write to it.
|
|
if (config.log) {
|
|
debug.addLog(config.log);
|
|
}
|
|
|
|
// If we're just doing a configuration test, exit here before starting any
|
|
// servers.
|
|
if (config.test) {
|
|
debug.log('Configuration test OK.');
|
|
process.exit(0);
|
|
}
|
|
|
|
var server;
|
|
if (ssl_config.enabled) {
|
|
server = https.createServer({
|
|
key: ssl_config.key,
|
|
cert: ssl_config.cert
|
|
}, function(req, res) {
|
|
res.writeHead(501);
|
|
res.end('HTTP/501 Use Websockets\n');
|
|
});
|
|
} else {
|
|
server = http.createServer(function() {});
|
|
}
|
|
|
|
var client_server = new JX.AphlictClientServer(server);
|
|
var admin_server = new JX.AphlictAdminServer();
|
|
|
|
client_server.setLogger(debug);
|
|
admin_server.setLogger(debug);
|
|
admin_server.setClientServer(client_server);
|
|
|
|
client_server.listen(config['client-port'], config['client-host']);
|
|
admin_server.listen(config['admin-port'], config['admin-host']);
|
|
|
|
debug.log('Started Server (PID %d)', process.pid);
|