fix: remove duplicate CheckInstallStep mount and .env hot-reload (#41)#151
Merged
Merged
Conversation
Two related sources of duplicate-handler accumulation in the bootstrap: 1. CheckInstallStep was mounted twice: once inside initializeControllers() and once unconditionally at the top level. The top-level mount has to stay because the install wizard must be reachable before MONGODB_URL is configured. Removed the inner mount so each startup registers it exactly once. 2. fs.watchFile on .env called initializeControllers() on every save, which re-ran .init(app) for ~60 route modules onto the same Express app instance (Express has no clean route un-registration) and spun another setInterval inside startInterval(). Removed the watcher; nodemon already restarts on file changes in dev, and production env changes require a process restart anyway. After this change initializeControllers() is only invoked once, from the MONGODB_URL startup gate. Closes #41 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bootstrap was registering duplicate handlers from two paths:
Duplicate
CheckInstallStepmount — mounted insideinitializeControllers()and again unconditionally at the top level. The top-level mount has to stay so the install wizard is reachable beforeMONGODB_URLis configured. Removed the inner mount..envwatcher re-ran init —fs.watchFile('/.env')calledinitializeControllers()on every save, which re-.init(app)s ~60 route modules onto the same Express app (no clean way to un-register routes) and spawned anothersetIntervalinsidestartInterval(). Removed the watcher; nodemon handles dev reloads and prod env changes require a restart anyway.After this change
initializeControllers()is invoked exactly once, from theMONGODB_URLstartup gate.Trade-off
Hot-reload of
.envno longer takes effect without restarting. This behavior was already broken (it caused the leaks above), so removing it is a correctness fix rather than a feature loss. If hot env reload is wanted later, it should be a separate function that refreshesconfig/process.envonly — never re-mounts routes.Test plan
MONGODB_URLunset, confirm CheckInstallStep is still reachable so the install wizard can run..envwhile the server runs (without nodemon); confirm theACTIVE CONNECTIONS:log line fires on a single cadence (not stacking).grep -n "initializeControllers" index.jsshows only the definition and the single startup call.Closes #41