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 => {
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;

8
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); }});
}

Loading…
Cancel
Save