[object Object]

← back to Contractwallpaper

add: clean-URL routes for /care /history /sourcing /trade /vocabulary + 404 guard middleware

eca0bc39e5f720be797189c75684532b8c407375 · 2026-05-25 20:56:52 -0700 · Steve

Files touched

Diff

commit eca0bc39e5f720be797189c75684532b8c407375
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon May 25 20:56:52 2026 -0700

    add: clean-URL routes for /care /history /sourcing /trade /vocabulary + 404 guard middleware
---
 server.js | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/server.js b/server.js
index cefe283..c5363c5 100644
--- a/server.js
+++ b/server.js
@@ -191,6 +191,11 @@ app.get('/sample/:handle', (req, res) => {
 // /about → served by the "short history" page (no dedicated about.html exists)
 app.get('/about', (req, res) => res.sendFile(path.join(__dirname, 'public', 'history.html')));
 
+// Clean-URL aliases for extension-less nav links (avoids 404s on /care, /history, etc.)
+for (const slug of ['care', 'history', 'sourcing', 'trade', 'vocabulary']) {
+  app.get('/' + slug, (req, res) => res.sendFile(path.join(__dirname, 'public', slug + '.html')));
+}
+
 // sitemap.xml + robots.txt for SEO
 app.get('/robots.txt', (req, res) => {
   res.type('text/plain').send(`User-agent: *
@@ -210,6 +215,13 @@ ${urls.map(u => `  <url><loc>https://contractwallpaper.com${u}</loc><changefreq>
 // 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 for everything else. Keeps prod logs
+// tidy and stops the express HTML 404 page from leaking the URL pattern.
+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;

← 40b9ebc fix: remove vendor leak in Ideas rail + add noreferrer to fb  ·  back to Contractwallpaper  ·  wire api-vendor-redact middleware (close vendors-facet leak) 00ce39f →