Skip to content

fix: remove duplicate CheckInstallStep mount and .env hot-reload (#41)#151

Merged
parth0025 merged 1 commit into
stagingfrom
fix/issue-41-duplicate-route-registration
May 15, 2026
Merged

fix: remove duplicate CheckInstallStep mount and .env hot-reload (#41)#151
parth0025 merged 1 commit into
stagingfrom
fix/issue-41-duplicate-route-registration

Conversation

@parth0025
Copy link
Copy Markdown
Collaborator

@parth0025 parth0025 commented May 14, 2026

Summary

Bootstrap was registering duplicate handlers from two paths:

  1. Duplicate CheckInstallStep mount — mounted inside initializeControllers() and again unconditionally at the top level. The top-level mount has to stay so the install wizard is reachable before MONGODB_URL is configured. Removed the inner mount.

  2. .env watcher re-ran initfs.watchFile('/.env') called initializeControllers() 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 another setInterval inside startInterval(). Removed the watcher; nodemon handles dev reloads and prod env changes require a restart anyway.

After this change initializeControllers() is invoked exactly once, from the MONGODB_URL startup gate.

Trade-off

Hot-reload of .env no 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 refreshes config/process.env only — never re-mounts routes.

Test plan

  • Boot the server, hit a CheckInstallStep route and confirm it responds normally.
  • Boot with MONGODB_URL unset, confirm CheckInstallStep is still reachable so the install wizard can run.
  • Edit .env while the server runs (without nodemon); confirm the ACTIVE CONNECTIONS: log line fires on a single cadence (not stacking).
  • grep -n "initializeControllers" index.js shows only the definition and the single startup call.

Closes #41

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>
@parth0025 parth0025 self-assigned this May 15, 2026
@parth0025 parth0025 merged commit a97fbf4 into staging May 15, 2026
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

Successfully merging this pull request may close these issues.

1 participant