Skip to content

Commit

Permalink
Merge pull request #29 from snyk/fix/https-cert-handling
Browse files Browse the repository at this point in the history
fix: https support relies on proper env vars
  • Loading branch information
adrukh authored Apr 13, 2017
2 parents 5cdbbdc + ea65e19 commit 894b1d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/webserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const stripEmptyRequestBody = (req, res, next) => {
next();
};

function main({ key = null, cert = null, port = 7341 } = {}, altPort = null) {
const http = (!key && !cert); // no https if there's no certs
function main({ httpsKey = null, httpsCert = null, port = 7341 } = {}, altPort = null) {
const http = (!httpsKey && !httpsCert); // no https if there's no certs
const https = http ? require('http') : require('https');
const app = express();

Expand All @@ -37,8 +37,8 @@ function main({ key = null, cert = null, port = 7341 } = {}, altPort = null) {

logger.info('local server listening @ %s', port);
const serverArgs = http ? [app] : [{
key: fs.readFileSync(key),
cert: fs.readFileSync(cert),
key: fs.readFileSync(httpsKey),
cert: fs.readFileSync(httpsCert),
}, app];

const server = https.createServer.apply(https, serverArgs).listen(port);
Expand Down
4 changes: 2 additions & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ function port() {
const echoServerPort = port();
const { app: echoServer, server } = webserver({
port: echoServerPort,
key: process.env.TEST_KEY, // Optional
cert: process.env.TEST_CERT, // Optional
httpsKey: process.env.TEST_KEY, // Optional
httpsCert: process.env.TEST_CERT, // Optional
});

echoServer.get('/echo-param/:param', (req, res) => {
Expand Down

0 comments on commit 894b1d5

Please sign in to comment.