From c07663aa7b9d82baa10de052ed6bb90dd0fb0d90 Mon Sep 17 00:00:00 2001 From: Anthony GAEREMYNCK <1@anthony.sh> Date: Sun, 2 Aug 2026 10:23:07 +0200 Subject: [PATCH] feat(seo): return a real 404 status for unmatched routes --- src/app.js | 2 +- test/staticServing.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/app.js b/src/app.js index 472715d..7535c00 100644 --- a/src/app.js +++ b/src/app.js @@ -270,7 +270,7 @@ export function createApp(config, prisma) { }) ); app.get(/^\/(?!api\/).*/, (req, res) => { - res.sendFile(path.join(frontendDist, 'index.html')); + res.status(404).sendFile(path.join(frontendDist, '404', 'index.html')); }); app.use((err, req, res, next) => { diff --git a/test/staticServing.test.js b/test/staticServing.test.js index b2cb439..4f34b50 100644 --- a/test/staticServing.test.js +++ b/test/staticServing.test.js @@ -17,6 +17,8 @@ beforeAll(async () => { frontendDist = await fs.mkdtemp(path.join(os.tmpdir(), 'converter-dist-')); await fs.mkdir(path.join(frontendDist, 'fr'), { recursive: true }); await fs.mkdir(path.join(frontendDist, 'assets'), { recursive: true }); + await fs.mkdir(path.join(frontendDist, '404'), { recursive: true }); + await fs.writeFile(path.join(frontendDist, '404', 'index.html'), 'not found'); await fs.writeFile( path.join(frontendDist, 'fr', 'index.html'), `fr home ${'x'.repeat(2000)}` @@ -77,3 +79,17 @@ describe('static asset serving', () => { expect(response.headers['content-encoding']).toBe('gzip'); }); }); + +describe('404 handling', () => { + it('returns a real 404 status for an unknown path', async () => { + const response = await request(app).get('/this-page-does-not-exist/'); + expect(response.status).toBe(404); + expect(response.text).toContain('not found'); + }); + + it('still serves a known route with 200', async () => { + const response = await request(app).get('/fr/'); + expect(response.status).toBe(200); + expect(response.text).toContain('fr home'); + }); +});