Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/http-server
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var colors = require('colors'),
opener = require('opener'),
argv = require('optimist')
.boolean('cors')
.boolean('auto')
.argv;

var ifaces = os.networkInterfaces();
Expand All @@ -32,6 +33,7 @@ if (argv.h || argv.help) {
' -U --utc Use UTC time format in log messages.',
'',
' -P --proxy Fallback proxy if the request cannot be resolved. e.g.: http://someurl.com',
' --auto Set proxy autoRewrite flag for proxy, handling 301/302 responses',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing auto to autoRewrite later, I think it would be simpler and more clear to use the option --auto-rewrite from the start instead. Otherwise I think this looks good.

'',
' -S --ssl Enable https.',
' -C --cert Path to ssl cert file (default: cert.pem).',
Expand Down Expand Up @@ -109,6 +111,10 @@ function listen(port) {
}
}

if (argv.auto) {
options.autoRewrite = true;
}

if (ssl) {
options.https = {
cert: argv.C || argv.cert || 'cert.pem',
Expand Down
3 changes: 2 additions & 1 deletion lib/http-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ function HttpServer(options) {
before.push(function (req, res) {
proxy.web(req, res, {
target: options.proxy,
changeOrigin: true
changeOrigin: true,
autoRewrite: options.autoRewrite
});
});
}
Expand Down