Browse Source

delay reading ssl cert files until needed

pull/89/head
BradfordMedeiros 8 years ago
parent
commit
129732483d
  1. 4
      src/getSSLSettings.js
  2. 8
      src/startServer.js

4
src/getSSLSettings.js

@ -41,8 +41,8 @@ const getOptions = () => {
const getSSLObject = opts => { const getSSLObject = opts => {
if (opts.sslkey && opts.sslcert){ if (opts.sslkey && opts.sslcert){
return ({ return ({
key: fs.readFileSync(path.resolve(opts.sslkey)), key: opts.sslkey,
cert: fs.readFileSync(path.resolve(opts.sslcert)), cert: opts.sslcert,
}); });
} }
return undefined; return undefined;

8
src/startServer.js

@ -4,6 +4,7 @@ const https = require('https');
const path = require('path'); const path = require('path');
const server = require('socket.io'); const server = require('socket.io');
const pty = require('pty.js'); const pty = require('pty.js');
const fs = require('fs');
const createRoutes = () => { const createRoutes = () => {
const app = express(); const app = express();
@ -43,12 +44,17 @@ const startTerminal = (theArgs, sshuser) => {
return term; 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 startServer = (theArgs, { onConnectionAccepted, onServerListen, onTerminalStart, onTerminalExit }) => {
const app = createRoutes(); const app = createRoutes();
let httpserv; let httpserv;
if (theArgs.runhttps) { 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 { } else {
httpserv = http.createServer(app).listen(theArgs.port, () => { if (onServerListen) { onServerListen(false); }}); httpserv = http.createServer(app).listen(theArgs.port, () => { if (onServerListen) { onServerListen(false); }});
} }

Loading…
Cancel
Save