Skip to content

Commit

Permalink
Merge pull request #742 from Ratcoder/master
Browse files Browse the repository at this point in the history
Fixes --proxy without a protocol throwing an uncaught error
  • Loading branch information
thornjad committed Oct 13, 2021
2 parents 86e8978 + 046fefa commit 93fbb75
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
14 changes: 13 additions & 1 deletion bin/http-server
Expand Up @@ -7,7 +7,9 @@ var colors = require('colors/safe'),
httpServer = require('../lib/http-server'),
portfinder = require('portfinder'),
opener = require('opener'),
fs = require('fs');

fs = require('fs'),
url = require('url');
var argv = require('minimist')(process.argv.slice(2), {
alias: {
tls: 'ssl'
Expand Down Expand Up @@ -160,6 +162,16 @@ function listen(port) {
}
}

if (proxy) {
try {
new url.URL(proxy)
}
catch (err) {
logger.info(colors.red('Error: Invalid proxy url'));
process.exit(1);
}
}

if (tls) {
options.https = {
cert: argv.C || argv.cert || 'cert.pem',
Expand Down
13 changes: 13 additions & 0 deletions test/cli.test.js
Expand Up @@ -101,3 +101,16 @@ test('setting mimeTypes via cli - directly', (t) => {
});
});
});

test('--proxy requires you to specify a protocol', (t) => {
t.plan(1);

const options = ['.', '--proxy', 'google.com'];
const server = startServer(options);

tearDown(server, t);

server.on('exit', (code) => {
t.equal(code, 1);
});
});

0 comments on commit 93fbb75

Please sign in to comment.