Websocket config should be similar to web #176

This commit is contained in:
Bryan Ashby 2018-04-23 19:03:35 -06:00
parent 6e94befd8b
commit a0cd8fed83
3 changed files with 39 additions and 17 deletions

View File

@ -230,13 +230,21 @@ function getDefaultConfig() {
firstMenuNewUser : 'sshConnectedNewUser', firstMenuNewUser : 'sshConnectedNewUser',
}, },
webSocket : { webSocket : {
port : 8810, // ws:// ws : {
// non-secure ws://
enabled : false, enabled : false,
securePort : 8811, // wss:// - must provide certPem and keyPem port : 8810,
},
wss : {
// secure ws://
// must provide valid certPem and keyPem
enabled : false,
port : 8811,
certPem : paths.join(__dirname, './../config/https_cert.pem'), certPem : paths.join(__dirname, './../config/https_cert.pem'),
keyPem : paths.join(__dirname, './../config/https_cert_key.pem'), keyPem : paths.join(__dirname, './../config/https_cert_key.pem'),
}, },
}, },
},
contentServers : { contentServers : {
web : { web : {

View File

@ -118,12 +118,15 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule {
// * insecure websocket (ws://) // * insecure websocket (ws://)
// * secure (tls) websocket (wss://) // * secure (tls) websocket (wss://)
// //
const config = _.get(Config, 'loginServers.webSocket') || { enabled : false }; const config = _.get(Config, 'loginServers.webSocket');
if(!config || true !== config.enabled || !(config.port || config.securePort)) { if(!_.isObject(config)) {
return; return;
} }
if(config.port) { const wsPort = _.get(config, 'ws.port');
const wssPort = _.get(config, 'wss.port');
if(true === _.get(config, 'ws.enabled') && _.isNumber(wsPort)) {
const httpServer = http.createServer( (req, resp) => { const httpServer = http.createServer( (req, resp) => {
// dummy handler // dummy handler
resp.writeHead(200); resp.writeHead(200);
@ -136,10 +139,10 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule {
}; };
} }
if(config.securePort) { if(_.isObject(config, 'wss') && true === _.get(config, 'wss.enabled') && _.isNumber(wssPort)) {
const httpServer = https.createServer({ const httpServer = https.createServer({
key : fs.readFileSync(Config.loginServers.webSocket.keyPem), key : fs.readFileSync(config.wss.keyPem),
cert : fs.readFileSync(Config.loginServers.webSocket.certPem), cert : fs.readFileSync(config.wss.certPem),
}); });
this.secure = { this.secure = {
@ -157,7 +160,7 @@ exports.getModule = class WebSocketLoginServer extends LoginServerModule {
} }
const serverName = `${ModuleInfo.name} (${serverType})`; const serverName = `${ModuleInfo.name} (${serverType})`;
const port = parseInt(_.get(Config, [ 'loginServers', 'webSocket', 'secure' === serverType ? 'securePort' : 'port' ] )); const port = parseInt(_.get(Config, [ 'loginServers', 'webSocket', 'secure' === serverType ? 'wss' : 'ws', 'port' ] ));
if(isNaN(port)) { if(isNaN(port)) {
Log.error( { server : serverName, port : port }, 'Cannot load server (invalid port)' ); Log.error( { server : serverName, port : port }, 'Cannot load server (invalid port)' );

View File

@ -27,12 +27,23 @@ don't already have it defined).
````hjson ````hjson
loginServers: { loginServers: {
webSocket : { webSocket : {
ws: {
// non-secure ws://
port: 8810 port: 8810
enabled: true enabled: true
securePort: 8811 }
wss: {
// secure-over-tls wss://
port: 8811
enabled: true
certPem: /path/to/https_cert.pem certPem: /path/to/https_cert.pem
keyPem: /path/to/https_cert_key.pem keyPem: /path/to/https_cert_key.pem
} }
// set proxied to true to allow TLS-terminated proxied connections
// containing the "X-Forwarded-Proto: https" header to be treated
// as secure
proxied: true
}
} }
```` ````