-
Notifications
You must be signed in to change notification settings - Fork 116
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
Added option to specify host address to bind servers to #37
Conversation
port: 80, | ||
|
||
// The host address in which the server should bind to. If not specified, | ||
// this argument will be ignored. | ||
host_address: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the convention for this would be to be called host
, cause you can also put a host name here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just default this to 127.0.0.1 and avoid binding without a host name and therefore preventing remote access by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess one thing to note is that is it a breaking change to some extent. If we look at the node docs for .listen
here (express's app.listen
does call http.listen
), when you don't specify a hostname, it will try to find any IPv4/IPv6 address.
What we could do is either add a note about the recommended way to setup the server bindings or maybe deprecate the old style method in favor of the new one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the purposes of this PR I agree not to change it, opened #38.
//TODO: add separate option to specify specific host address for HTTPS server to bind to ??? | ||
if (typeof config.host_address === 'string') { | ||
self.httpsInstance = httpsServer.listen(config.httpsPort, config.host_address); | ||
self.log("Listening on HTTPS port " + config.httpsPort + " on address " + config.host_address); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: maybe should just say something like "Listing on https://host:port", someone reading the log can just copy paste it into a browser.
self.log("Listening on HTTPS port " + config.httpsPort + " on address " + config.host_address); | ||
} else { | ||
self.httpsInstance = httpsServer.listen(config.httpsPort); | ||
self.log("Listening on HTTPS port " + config.httpsPort); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would say "Listening on https://127.0.0.1:port or localhost ...
} else { | ||
self.httpInstance = self.express.listen(config.port); | ||
self.log("Listening on HTTP port " + config.port); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading this, are we creating both an http and https endpoint? Shouldn't be just https if that's enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, since the initial check already checks if https is enabled, and if so, will then proceed to initialize httpsInstance
here. Otherwise, only the httpInstance
should contain a server instance.
…or starting the server
it("mounts hello world app (HTTP only)", function() { | ||
testServer = alexaAppServer.start({ | ||
port: 3000, | ||
host_address: "127.0.0.1", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be host
. The test isn't actually checking that these values were used, start the server with these and then compare them from the express instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to test it via referring to the actual address (like http://127.0.0.1:3000
and https://127.0.0.1:6000
) the express server is hosting to, since it's not possible to check for the IP from the express instance.
certificate: 'cert.cer' | ||
}); | ||
|
||
return request(testServer.express) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just like above.
@@ -149,11 +151,13 @@ var appServer = function(config) { | |||
|
|||
self.start = function() { | |||
// Instantiate up the server | |||
//TODO: add i18n support (i18n-node might be a good look) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: personally I don't find these TODOs useful, because we have Github issues. If you want them there, maybe add a link to the github issue opened for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I initially put the TODO's so that if anyone else is trying to fix any current issues, they know where in the code to look for. I like the idea of adding the links to the issues, so thanks!
try { // These two lines below can fail it the certs were generated incorrectly. But we can continue startup without HTTPS | ||
var httpsServer = https.createServer(credentials, self.express); // create the HTTPS server | ||
|
||
//TODO: add separate option to specify specific host address for HTTPS server to bind to ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny annoying nitpick. Can we add a space after //
, so // TODO:
, hurts me every time :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem!
var alexaAppServer = require("../index"); | ||
|
||
// used so that testing https requests will work properly | ||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll merge, however it feels like this should be set per-test, or in a beforeEach
and then reset back in an afterEach
.
Merged, thanks. |
This resolves issue #5.