npm install worked. CI passed. Production was empty.
Last month. Client says search is broken. I check. Search endpoint returns 404.
Weird thing is the code definitely existed. Search component imported SearchService. SearchService called GET /api/internal/search. Route just... wasn't registered anywhere in Express.
Tracing it down
I went through it line by line. Search imports SearchService. Service makes that call. Where does it go?
Nowhere. Wasn't in app.use anywhere.
Local worked because of some weird hot reload setup I had from debugging. That route existed because I'd imported it in a test file during a spike. Never made it to the actual production router.
Why CI didn't catch it
npm install. npm run build. Tests pass. Image pushes. Server pulls. Container restarts. All green.
Tests mocked the service layer directly. Never actually called the endpoint through Express. Mock said "here's what SearchService returns" and the test believed it.
So route registration was never validated. Ever.
The fix was literally one line:
app.use('/api', searchRouter)
That's it. Missing line. 404 on production.
Still annoyed about it
Took longer than I'd like to admit. Added that one line, worked immediately.
Now I have smoke tests that hit real endpoints. At least one test that validates route registration actually exists. Should've had that before.
Top comments (0)