Skip to content

fix(backend): restore server boot - resolve six independent crashes - #1010

Open
Rudra-clrscr wants to merge 1 commit into
Userunknown84:mainfrom
Rudra-clrscr:fix/backend-boot-crash
Open

fix(backend): restore server boot - resolve six independent crashes#1010
Rudra-clrscr wants to merge 1 commit into
Userunknown84:mainfrom
Rudra-clrscr:fix/backend-boot-crash

Conversation

@Rudra-clrscr

@Rudra-clrscr Rudra-clrscr commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Problem

upstream/main currently cannot boot at all. Each require-time crash was
masking the next one, so fixing this required working through six separate,
unrelated bugs one at a time until node server.js actually reached
"Server running".

What's fixed

  1. middleware/rateLimiter.js — an orphaned function-body fragment
    (res.setHeader(...), next()) sat at module top level, referencing
    res/remaining/next that don't exist there, crashing on require().
    Traced via git log -S to the "Add API rate limit dashboard" commit —
    that feature's real data source is the separate GET /api/v1/analytics/rate-limit
    route, so this fragment was dead on arrival. Deleted.
  2. middleware/poisoningGuard.jstrainingRateLimiter's keyGenerator
    returned a raw IP without express-rate-limit v7's required
    ipKeyGenerator() wrapper (ERR_ERL_KEY_GEN_IPV6). Fixed to match the
    pattern already used everywhere else in rateLimiter.js.
  3. routes/feedbackRoutes.js — required ../middleware/auth and
    ../models/Feedback, neither of which exist. Fixed to
    ../middleware/authMiddleware and ../models/UserFeedback.
  4. services/bulkPredictService.js — required by
    bulkPredictController.js but never committed. Added it, reusing the
    existing ML-API circuit-breaker/fallback pattern from
    predictionRoutes.js for per-row resilience on bulk uploads.
  5. routes/authRoutes.js — 1529 lines of duplicated dead logic
    (generateToken, buildAuthResponse, register, login each declared
    twice) with zero actual router.* registrations/api/auth has
    been completely non-functional. Replaced with a clean router delegating
    to authController.js (which already has full, correct implementations
    of everything needed). That router depends on
    backend/validators/auth.validator.js, deleted from upstream at some
    point — recreated it with rules mirrored from models/User.js's own
    schema constraints.
  6. utils/utils/emailTransporter.js — nested one directory too deep by
    mistake (the file's own header comment confirms the intended path).
    Moved to utils/emailTransporter.js.
  7. routes/analyticsRoutes.js — required a nonexistent ../models/Prediction
    from ~85 lines of dead code sitting after the file's own
    module.exports, superseded by the controller-based routes registered
    earlier in the same file. The one route in that dead block the frontend
    actually calls, GET /accuracy, had a straight copy-paste of unrelated
    rate-limit-dashboard logic (down to an undefined cache reference)
    instead of computing accuracy. Reimplemented against UserFeedback
    (predicted_label vs correct_label) to match the shape
    AccuracyMeter.jsx actually reads.

Verification

Recommend merging this first — none of #1000-#1003's endpoints are
reachable in production until the server can actually boot.

upstream/main currently cannot boot at all; each require-time crash
was masking the next one, so this required working through them one
at a time until `node server.js` actually reaches "Server running".

- middleware/rateLimiter.js: a stray function-body fragment
  (res.setHeader/next() referencing undefined res/remaining/next) sat
  at module top level, crashing on require(). Confirmed dead via `git
  log -S`: it was accidentally committed whole-cloth in "feat: Add API
  rate limit dashboard", whose actual data source is the separate,
  self-contained GET /api/v1/analytics/rate-limit route - nothing
  references these lines. Deleted them.
- middleware/poisoningGuard.js: trainingRateLimiter's keyGenerator
  returned a raw IP without express-rate-limit's ipKeyGenerator()
  helper, which v7 rejects at startup (ERR_ERL_KEY_GEN_IPV6). Fixed
  to match the pattern already used everywhere else in
  middleware/rateLimiter.js.
- backend/routes/feedbackRoutes.js: required '../middleware/auth' and
  '../models/Feedback', neither of which exist - the real paths are
  '../middleware/authMiddleware' (used by every other route file) and
  '../models/UserFeedback' (the only feedback model in the repo).
- backend/controllers/bulkPredictController.js requires
  '../services/bulkPredictService', which was never committed. Added
  it: batches rows through the same ML API /predict call and
  circuit-breaker/fallback pattern predictionRoutes.js already uses
  for single predictions, isolating per-row failures instead of
  aborting the whole upload.
- backend/routes/authRoutes.js was 1529 lines of duplicated dead
  logic (generateToken, buildAuthResponse, register, login, etc. each
  declared twice) with zero actual router.* registrations - /api/auth
  has been completely non-functional. authController.js already has
  full, correct implementations of everything this router needs;
  replaced the file with the router that actually wires them up
  (verified this exact rewrite already exists, reviewed, and pushed
  on the fix/backend-eslint-errors branch). That router depends on
  backend/validators/auth.validator.js, which upstream deleted at
  some point after that branch forked - recreated it with validation
  rules mirrored from models/User.js's own schema constraints
  (username 3-30 chars/alphanumeric+underscore, valid email, password
  min 6 chars).
- backend/utils/utils/emailTransporter.js (double-nested by mistake -
  the file's own header comment says `backend/utils/emailTransporter.js`)
  moved to the path authController.js already expects it at.
- backend/routes/analyticsRoutes.js required a '../models/Prediction'
  that doesn't exist, used only by ~85 lines of legacy /trends and
  /analytics handlers sitting *after* the file's module.exports -
  dead weight superseded by the analyticsController-based routes
  registered earlier in the same file (confirmed neither shadowed
  path is called by the frontend). The one route in that dead block
  the frontend actually calls, GET /accuracy, had a straight copy-paste
  of the rate-limit-dashboard body (down to an undefined `cache`
  reference) instead of computing accuracy at all; reimplemented it
  against UserFeedback (predicted_label vs. correct_label) to match
  the {accuracy, total, correct, incorrect} shape AccuracyMeter.jsx
  actually reads.

Verified by booting the full server with dummy env vars end-to-end:
reaches "Server running on http://localhost:3000" and stays up
(Redis/MongoDB connection failures are handled by existing fallback
logic, not fatal). Confirmed routing/middleware wiring via curl:
GET /health -> 200; POST /api/auth/register and /login -> 400 on an
empty body (validators/auth.validator.js firing correctly, not a
crash or 404); POST /api/feedback, GET /api/v1/analytics/{summary,accuracy},
GET /api/poisoning/status -> 401 (protect middleware reached and
enforced, routes are live); GET /this-route-does-not-exist -> 404
control. `node --check` and `eslint` clean on every touched file (no
new errors; pre-existing warnings/errors elsewhere confirmed via
diffing against unmodified upstream/main).
Copilot AI review requested due to automatic review settings July 28, 2026 17:15
@vercel

vercel Bot commented Jul 28, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Userunknown84 Userunknown84 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AuthRoutes.js check karo kafi code remove ho raha h .That code is need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants