Begin generalizing Aphlict server to prepare for clustering/sensible config file
Summary: Ref T10697. Currently, `aphlict` takes a ton of command line flags to configure exactly one admin server and exactly one client server. I want to replace this with a config file. Additionally, I plan to support: - arbitrary numbers of listening client ports; - arbitrary numbers of listening admin ports; - SSL on any port. For now, just transform the arguments to look like they're a config file. In the future, I'll load from a config file instead. This greater generality will allow you to do stuff like run separate HTTP and HTTPS admin ports if you really want. I don't think there's a ton of use for this, but it tends to make the code cleaner anyway and there may be some weird cross-datacneter cases for it. Certainly, we undershot with the initial design and lots of users want to terminate SSL in nginx and run only HTTP on this server. (Some sort-of-plausible use cases are running separate HTTP and HTTPS client servers, if your Phabricator install supports both, or running multiple HTTPS servers with different certificates if you have a bizarre VPN.) Test Plan: Started Aphlict, connected to it, sent myself test notifications, viewed status page, reviewed logfile. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10697 Differential Revision: https://secure.phabricator.com/D15700
This commit is contained in:
@@ -12,11 +12,16 @@ var WebSocket = require('ws');
|
||||
JX.install('AphlictClientServer', {
|
||||
|
||||
construct: function(server) {
|
||||
this.setLogger(new JX.AphlictLog());
|
||||
server.on('request', JX.bind(this, this._onrequest));
|
||||
|
||||
this._server = server;
|
||||
this._lists = {};
|
||||
},
|
||||
|
||||
properties: {
|
||||
logger: null,
|
||||
},
|
||||
|
||||
members: {
|
||||
_server: null,
|
||||
_lists: null,
|
||||
@@ -28,6 +33,25 @@ JX.install('AphlictClientServer', {
|
||||
return this._lists[path];
|
||||
},
|
||||
|
||||
log: function() {
|
||||
var logger = this.getLogger();
|
||||
if (!logger) {
|
||||
return;
|
||||
}
|
||||
|
||||
logger.log.apply(logger, arguments);
|
||||
|
||||
return this;
|
||||
},
|
||||
|
||||
_onrequest: function(request, response) {
|
||||
// The websocket code upgrades connections before they get here, so
|
||||
// this only handles normal HTTP connections. We just fail them with
|
||||
// a 501 response.
|
||||
response.writeHead(501);
|
||||
response.end('HTTP/501 Use Websockets\n');
|
||||
},
|
||||
|
||||
listen: function() {
|
||||
var self = this;
|
||||
var server = this._server.listen.apply(this._server, arguments);
|
||||
@@ -38,7 +62,7 @@ JX.install('AphlictClientServer', {
|
||||
var listener = self.getListenerList(path).addListener(ws);
|
||||
|
||||
function log() {
|
||||
self.getLogger().log(
|
||||
self.log(
|
||||
util.format('<%s>', listener.getDescription()) +
|
||||
' ' +
|
||||
util.format.apply(null, arguments));
|
||||
@@ -97,10 +121,6 @@ JX.install('AphlictClientServer', {
|
||||
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
properties: {
|
||||
logger: null,
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user