Express connection logic didn't catch failed connections - #45492
Conversation
|
Preview URLs (1 page) (comment last updated: 2026-09-04 07:23:16) |
The bin/www generated by express-generator starts the HTTP server unconditionally, so simply fixing the connectMongoose() try/catch logic wasn't enough: readers following the tutorial would still end up with a server that starts regardless of whether the database connected. Move server creation into a startServer() function that only runs once connectMongoose() resolves, matching the upstream fix in mdn/express-locallibrary-tutorial#367. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018BoWRns9KXjAdyMZMeQ4g2
|
Note, every time I need to make an update like this I start coming around to the idea that we should stop using the generator and create our own template starting point. What I'd really like is an expert to update the current generator :-) |
|
This pull request has merge conflicts that must be resolved before it can be merged. |
Agreed!! Well I might be investing in #41604. Stay tuned. |
| var server; | ||
|
|
||
| function startServer() { | ||
| server = http.createServer(app); | ||
|
|
||
| server.listen(port); | ||
| server.on("error", onError); | ||
| server.on("listening", onListening); | ||
| } |
There was a problem hiding this comment.
Ugh, I hate this so much. Violates a bunch of code style guidelines. But I guess you really don't have better choices at this point.
I'll make starter code of our own.
There was a problem hiding this comment.
Maybe fork the code generator. There is a lot to be said for automated setup.
Josh-Cena
left a comment
There was a problem hiding this comment.
Rubber stamping since you already have another PR
Screw the other PR. If you want to fix this, propose a replacement. I took the easy road because to me this is just boilerplate. |
|
Yes I'm happy with this 😄 |
There was some non working connection logic in - a non-awaiting promise in a try-catch.
This was fixed and tested in mdn/express-locallibrary-tutorial#367
This fell out of #45473