← back to Handcraftedwallpaper
add 404-guard: JSON for /api/*, index.html fallback for everything else
2646f8f1a443d07bb52eac6b9dee84052141bb28 · 2026-05-25 21:06:35 -0700 · Steve Abrams
Files touched
Diff
commit 2646f8f1a443d07bb52eac6b9dee84052141bb28
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon May 25 21:06:35 2026 -0700
add 404-guard: JSON for /api/*, index.html fallback for everything else
---
server.js | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/server.js b/server.js
index a396597..f9b319e 100644
--- a/server.js
+++ b/server.js
@@ -260,6 +260,12 @@ if (catalog) catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
}
PRODUCTS_NICHE = PRODUCTS.filter(nicheFit);
console.log(`[${__SITE}] niche filter: kept ${PRODUCTS_NICHE.length} of ${PRODUCTS.length}`);
+ // 404 guard — JSON for /api/*, fall back to index.html for SPA-style nav,
+ // explicit 404 text otherwise. Mounted LAST so all real routes win.
+ app.use((req, res) => {
+ if (req.path.startsWith('/api/')) return res.status(404).json({ error: 'not found', path: req.path });
+ res.status(404).sendFile(path.join(__dirname, 'public', 'index.html'));
+ });
app.listen(PORT, '127.0.0.1', () => {
console.log(`handcraftedwallpaper listening on http://127.0.0.1:${PORT}`);
});
← 5aa683a wire api-vendor-redact middleware — mount first so all /api/
·
back to Handcraftedwallpaper
·
scrub customer-facing surface: hardcode 'Designer Wallcoveri d4c15d5 →