3.0 KiB
3.0 KiB
Iteration Log - 2026-07-24-1015 - Restore Next.js Middleware Routing (Ad-hoc)
Request
The user reported an error/bug/crash ("This page couldn't load" screen) after logging in or loading the app on https://demoplace.my.id/.
Steps Taken
- System Health Check (SSH):
- Checked PM2 status:
backone-backend,backone-frontend, andbackone-proxywere online, though proxy had high restarts from previous configurations. - Checked proxy logs (
logs/proxy-out.log): Connected successfully to MongoDB, schedulers active, deltas fetching successfully. - Checked frontend logs (
logs/frontend-error.log): Found older chunk-mismatch warnings ("Failed to find Server Action...") and recurring Node 18 crypto warnings.
- Checked PM2 status:
- Root Cause Identification:
- Analyzed previous changes which renamed
src/middleware.tstosrc/proxy.ts(exporting aproxyfunction) based on an experimental Next.js 16 deprecation warning. - Discovered that when using
src/proxy.tsin Next.js, the production build (npm run build) generated an emptymiddleware-manifest.json("middleware": {}), resulting in no server-side authentication checks or redirects.
- Analyzed previous changes which renamed
- TDD Setup:
- Wrote a new TDD test: middleware_verification_test.js asserting that
src/middleware.tsexists and exports the correctmiddlewarefunction. - Ran
node test/middleware_verification_test.jsand confirmed it failed as expected.
- Wrote a new TDD test: middleware_verification_test.js asserting that
- Resolution:
- Created middleware.ts with the proper
middlewarefunction and matches. - Deleted the obsolete
src/proxy.tsfile. - Ran local build
npm run buildand verified thatmiddleware-manifest.jsonis now correctly populated with routing matches. - Ran the TDD test again; it passed successfully!
- Created middleware.ts with the proper
- Deployment & Verification:
- Deployed updates via SFTP using
node scripts/deploy-sftp.jsand reloaded PM2. - Verified that
/correctly redirects to/loginvia remote command checks. - Ran integration tests test-remote-me.js and test-remote-summary.js to verify API data flows. Both returned
200 OKwith valid data.
- Deployed updates via SFTP using
Current State
- The Next.js frontend has server-side routing restored via the correct
middleware.tssetup. - Authentication checks and redirects work correctly.
- Integration tests and API data fetches pass cleanly on production.
Considerations for Next Time
- Although Next.js 16 shows a warning recommending renaming
middleware.tstoproxy.ts, Next.js's standalone compiler support for theproxy.tsconvention is still experimental and can produce empty middleware manifests under certain configurations. Restoring the standardmiddleware.tsnaming ensures production builds are stable.