[object Object]

← back to Wallco Ai

Redirect /api/design/{null,undefined,NaN} home too (belt-and-suspenders for stale-link/missing-id navigations)

66f0082cfcd25c39b71c296d11ba52074040d5a6 · 2026-06-01 13:33:32 -0700 · Steve Abrams

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

Files touched

Diff

commit 66f0082cfcd25c39b71c296d11ba52074040d5a6
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Mon Jun 1 13:33:32 2026 -0700

    Redirect /api/design/{null,undefined,NaN} home too (belt-and-suspenders for stale-link/missing-id navigations)
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---
 server.js | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/server.js b/server.js
index 6849e11..44b5dd8 100644
--- a/server.js
+++ b/server.js
@@ -469,6 +469,10 @@ app.get('/api/coordinates/ai', async (req, res) => {
 // Send the visitor home instead.
 app.get(['/api/design', '/api/design/'], (req, res) => res.redirect(302, '/'));
 app.get('/api/design/:id', (req, res) => {
+  // Belt-and-suspenders: a frontend bug or stale link can land a visitor on
+  // /api/design/null|undefined|NaN (the stringified result of a missing id).
+  // Treat those like the bare path → send home instead of a 400 JSON blob.
+  if (['null', 'undefined', 'NaN', ''].includes(String(req.params.id))) return res.redirect(302, '/');
   const id = parseInt(req.params.id, 10);
   if (!Number.isFinite(id) || id < 1) return res.status(400).json({ error: 'bad id' });
   const snap = DESIGNS.find(d => d.id === id);

← 8a607a0 Add publish-ready-batch.sh: curator-force-publish the 18 cen  ·  back to Wallco Ai  ·  SECURITY: admin-gate isLocalhost no longer trusts Host heade 624d542 →