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

If port can be converted to a number convert it #321

Closed
gsf opened this issue Oct 24, 2012 · 3 comments
Closed

If port can be converted to a number convert it #321

gsf opened this issue Oct 24, 2012 · 3 comments

Comments

@gsf
Copy link

gsf commented Oct 24, 2012

I'd like to set up a proxy server like so:

var httpProxy = require('http-proxy');

var port = process.env.PORT || 9876;
var proxiedHost = process.env.PROXIEDHOST || '127.0.0.1';
var proxiedPort = process.env.PROXIEDPORT || 8765;

httpProxy.createServer(proxiedPort, proxiedHost).listen(port);

If I set an environment variable for PORT I'm fine but doing the same for PROXIEDPORT breaks things because it expects a number instead of a string. Looks like node handles this in the net library with a handy toNumber function.

(Also, as an aside, it would be nice if the proxied host defaulted to 127.0.0.1 when missing that parameter.)

@Southern
Copy link
Contributor

Southern commented Nov 6, 2012

If you want to turn it into a number, you should use:

var proxiedPort = parseInt(process.env.PROXIEDPORT) || 8765;

@gsf
Copy link
Author

gsf commented Nov 6, 2012

I prefer

var proxiedPort = +process.env.PROXIEDPORT || 8765;

but I think others might get caught up on this as well, so it should be fixed in the project.

@Southern
Copy link
Contributor

Southern commented Nov 6, 2012

Fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants