[object Object]

← back to Chinoiseriewallpaper

add 404-guard middleware

b78efdd7b67b0afcea2257e150c54c8fa4d8655c · 2026-05-25 20:55:29 -0700 · Steve Abrams

Final catch-all returns JSON for /api/* misses and a lightweight branded
HTML page for everything else. Sits after the catalog mount so it only
fires when nothing upstream matched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files touched

Diff

commit b78efdd7b67b0afcea2257e150c54c8fa4d8655c
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon May 25 20:55:29 2026 -0700

    add 404-guard middleware
    
    Final catch-all returns JSON for /api/* misses and a lightweight branded
    HTML page for everything else. Sits after the catalog mount so it only
    fires when nothing upstream matched.
    
    Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---
 server.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/server.js b/server.js
index cb7d8b4..dfcd6d9 100644
--- a/server.js
+++ b/server.js
@@ -296,6 +296,18 @@ app.get('/', (req, res) => {
 // 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/*, lightweight HTML otherwise ────────────────
+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/html').send(
+    '<!doctype html><meta charset="utf-8"><title>Not found</title>' +
+    '<style>body{font-family:Cormorant Garamond,Georgia,serif;background:#f5f1e8;color:#0a0a0a;text-align:center;padding:80px 20px}h1{font-size:48px;font-weight:300;margin:0 0 12px}p{font-size:16px;color:#6e6e68;margin:0 0 24px}a{color:#0a0a0a;text-decoration:underline}</style>' +
+    '<h1>Not found</h1><p>The page you requested isn&rsquo;t here.</p><p><a href="/">Return home</a></p>'
+  );
+});
+
 // Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
 (async () => {
   let loaded = false;

← e041ec6 add noreferrer to every target=_blank link  ·  back to Chinoiseriewallpaper  ·  homepage rails: motif rail sections + pills strip wired to / 3e1bbcd →