-
-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
Include listen errors in app.listen() callback #2623
Conversation
You can call This is also pretty breaking, because no one has been adding |
Also, if you were just adding this for the listening error, the app.listen(3000, function (err) {
// ... do stuff
}) |
@dougwilson Ok, thats cool, it was just a one line change so I figured I would do it and see your thoughts. Your points make perfect sense, I guess I have just never used multiple listens (I use nginx for ssl term). For the callback scenario, maybe I am doing something wrong, but the process.on('uncaughtException', function(err) {
console.error('Uncaught: ', err);
});
app.listen(app.get('port'), app.get('hostname'), function(err) {
if (err) {
return console.error('Error starting server', err);
}
console.log('Listeneing');
}); And the output is:
This situation is the only reason I thought this might be a nicer api, since the best one is apparently not working correctly now. |
Oops, I was not remembering correctly. The |
Ignoring the fact that i didn't change the tests, what do you think of this: wesleytodd@a8bc849 Also ignore the tabs, I would fix those up before submitting. :) |
In general, looks fine. I would skip manipulating the |
02d76ae
to
d1aefa2
Compare
Ok, hows that? |
lib/application.js
Outdated
if (typeof args[args.length - 1] === 'function'){ | ||
var done = Array.prototype.pop.call(args); | ||
eeFirst([[server, 'error', 'listening']], function(err, ee, event, eventArgs){ | ||
done.apply(this, eventArgs); |
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 probably use the same context
as the listening event does: against ee
instead of app
.
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.
Good call
d1aefa2
to
8cfd62a
Compare
Let me know if you want me to change anything else!! |
Thanks, @wesleytodd , looks fine and targeted for 4.13 :) |
var app = express(); | ||
var app2 = express(); | ||
|
||
var server = app.listen(9999, function(err){ |
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.
Can this port number be made dynamic? Getting some race conditions where the Express suite is running multiples times on the same machine and they all want to use port 9999. Just have app
listen randomly and have app2
listen to whatever port app
is listening on should work.
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.
Yeah, I can make this change for sure. Let me know if you also want me to move this PR to the 5.0 branch and I will do it all at once.
Ok, cool, I got your changes all fixed up :) I found while testing that there are some issues with adding this in 4.x, namely that people are unconditionally assuming the callback means the server is up. I definitely love this convenience and will have it land in 5.0 instead \m/ |
Sounds good!! let me know if there is anything else you need from me, but it looks like it is all good! |
5f268a4
to
9848645
Compare
If this is slated for 5, should I re-make this PR against the 5.0 branch? Or are you pulling in the change manually? If so I can close this out. |
Closed in favor of #3216 |
I know that you can listen on the server instance, but it seems like this might be nicer to just proxy up the error event. Thoughts?