[object Object]

← back to Corkwallcovering

add 404-guard middleware (JSON for /api/*, text otherwise)

99cc085db84e3f4d3bcff4e6c8f72ca51188e212 · 2026-05-25 20:57:20 -0700 · SteveStudio2

Files touched

Diff

commit 99cc085db84e3f4d3bcff4e6c8f72ca51188e212
Author: SteveStudio2 <steve@designerwallcoverings.com>
Date:   Mon May 25 20:57:20 2026 -0700

    add 404-guard middleware (JSON for /api/*, text otherwise)
---
 server.js | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/server.js b/server.js
index f65c26d..726af29 100644
--- a/server.js
+++ b/server.js
@@ -208,6 +208,13 @@ ${urls.map(u => `  <url><loc>https://corkwallcovering.com${u}</loc><changefreq>w
 // Admin catalog CRUD — /admin/catalog (basic-auth) + /api/admin/* REST.
 if (catalog) catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
 
+// 404 guard — JSON for /api/*, plain text otherwise. Registered last so it
+// only fires when no route or static asset matched.
+app.use((req, res) => {
+  if (req.path.startsWith('/api/')) return res.status(404).json({ error: 'not_found', path: req.path });
+  res.status(404).type('text/plain').send('Not found');
+});
+
 // Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
 (async () => {
   let loaded = false;

← 7d043ab fix /api/facets total: report niche-filtered count, not raw  ·  back to Corkwallcovering  ·  redact p.vendor in rail-card (Ideas rails) — show Designer W 5c69aee →