Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #246: Add option --auto to set proxy option autoRewrite #247

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
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