From 129732483df792b6dc99f5301e6ca3584700b7bb Mon Sep 17 00:00:00 2001 From: BradfordMedeiros Date: Mon, 29 May 2017 02:02:08 -0700 Subject: [PATCH] delay reading ssl cert files until needed --- src/getSSLSettings.js | 4 ++-- src/startServer.js | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/getSSLSettings.js b/src/getSSLSettings.js index 64a44c8..de310bf 100644 --- a/src/getSSLSettings.js +++ b/src/getSSLSettings.js @@ -41,8 +41,8 @@ const getOptions = () => { const getSSLObject = opts => { if (opts.sslkey && opts.sslcert){ return ({ - key: fs.readFileSync(path.resolve(opts.sslkey)), - cert: fs.readFileSync(path.resolve(opts.sslcert)), + key: opts.sslkey, + cert: opts.sslcert, }); } return undefined; diff --git a/src/startServer.js b/src/startServer.js index 1ec8b1a..b305c88 100644 --- a/src/startServer.js +++ b/src/startServer.js @@ -4,6 +4,7 @@ const https = require('https'); const path = require('path'); const server = require('socket.io'); const pty = require('pty.js'); +const fs = require('fs'); const createRoutes = () => { const app = express(); @@ -43,12 +44,17 @@ const startTerminal = (theArgs, sshuser) => { return term; }; +const readSSLOptions = sslOpts => ({ + key: fs.readFileSync(path.resolve(opts.sslkey)), + cert: fs.readFileSync(path.resolve(opts.sslcert)), +}); + const startServer = (theArgs, { onConnectionAccepted, onServerListen, onTerminalStart, onTerminalExit }) => { const app = createRoutes(); let httpserv; if (theArgs.runhttps) { - httpserv = https.createServer(theArgs.ssl, app).listen(theArgs.port, () => { if (onServerListen) {onServerListen(true); }}); + httpserv = https.createServer(readSSLOptions(theArgs.ssl), app).listen(theArgs.port, () => { if (onServerListen) {onServerListen(true); }}); } else { httpserv = http.createServer(app).listen(theArgs.port, () => { if (onServerListen) { onServerListen(false); }}); }