← back to Dw Pitch Followup
Add catch-all: unknown non-api GETs redirect to / instead of raw Cannot GET 404
fc4911dc31758d93a693b50fdc143f2bd6fbece5 · 2026-08-06 08:16:42 -0700 · Steve Abrams
Stray deep-links / browser-autofilled paths now open the viewer instead of
Express's raw 'Cannot GET /path'. Scoped so /api/* still returns JSON 404s
(never redirect an API call — fetch() must see the real failure).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Files touched
Diff
commit fc4911dc31758d93a693b50fdc143f2bd6fbece5
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu Aug 6 08:16:42 2026 -0700
Add catch-all: unknown non-api GETs redirect to / instead of raw Cannot GET 404
Stray deep-links / browser-autofilled paths now open the viewer instead of
Express's raw 'Cannot GET /path'. Scoped so /api/* still returns JSON 404s
(never redirect an API call — fetch() must see the real failure).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
server.js | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/server.js b/server.js
index d6a3c9e..4ce3bf7 100644
--- a/server.js
+++ b/server.js
@@ -873,6 +873,14 @@ app.post('/api/notes-batch', async (req, res) => {
} catch (e) { res.status(500).json({ error: e.message }); }
});
+// Catch-all (MUST stay last, just before listen): a GET to any unknown, non-/api
+// path lands on the app instead of Express's raw "Cannot GET /path" 404 — so a
+// stray deep-link or a browser-autofilled path just opens the viewer at '/'.
+app.get(/^\/(?!api(\/|$)).*/, (_req, res) => res.redirect('/'));
+// Unknown /api/* stays an honest JSON 404 — never redirect an API call, or fetch()
+// would silently follow the 302 to HTML instead of seeing the real failure.
+app.use('/api', (_req, res) => res.status(404).json({ error: 'not found' }));
+
app.listen(PORT, '127.0.0.1', () => {
console.log(`[dw-pitch-followup] listening on http://127.0.0.1:${PORT} (auth ${BASIC_AUTH.split(':')[0]} / …) letters via ${LETTER_MODEL}`);
});
← 61ac5f6 auto-save: 2026-07-31T20:00:42 (1 files) — data/suppress.jso
·
back to Dw Pitch Followup
·
Fix pitch-rebuild launchd: valid plist + once-daily 2:00 AM 264deba →