← back to Raffiawalls
clean-URL routes for /history /vocabulary /sourcing /care /trade + 404-guard catch-all
118686d249df87f6140afbe4654f7e87f6ed97f0 · 2026-05-25 21:26:52 -0700 · Steve Abrams
Files touched
Diff
commit 118686d249df87f6140afbe4654f7e87f6ed97f0
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon May 25 21:26:52 2026 -0700
clean-URL routes for /history /vocabulary /sourcing /care /trade + 404-guard catch-all
---
server.js | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/server.js b/server.js
index 40b7bf7..26cef67 100644
--- a/server.js
+++ b/server.js
@@ -203,6 +203,18 @@ 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 routes for extension-less nav links (history.html, care.html, etc.
+// are linked across the site as /history, /care, /vocabulary, /sourcing, /trade).
+// Static middleware would 404 these without explicit routes.
+const CLEAN_PAGES = ['history', 'vocabulary', 'sourcing', 'care', 'trade'];
+for (const slug of CLEAN_PAGES) {
+ app.get('/' + slug, (req, res) => {
+ const file = path.join(__dirname, 'public', slug + '.html');
+ if (!fs.existsSync(file)) return res.status(404).send('Not found');
+ res.sendFile(file);
+ });
+}
+
// sitemap.xml + robots.txt for SEO
app.get('/robots.txt', (req, res) => {
res.type('text/plain').send(`User-agent: *
@@ -222,6 +234,14 @@ ${urls.map(u => ` <url><loc>https://raffiawalls.com${u}</loc><changefreq>weekly
// Admin catalog CRUD — /admin/catalog (basic-auth) + /api/admin/* REST.
if (catalog) catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
+// 404-guard — anything unmatched (including stray /server.js.bak, /*.pre-*, or
+// any other path that slipped past static + routes) returns a clean 404 instead
+// of falling through to express's default "Cannot GET …" leak.
+app.use((req, res) => {
+ if (req.path.startsWith('/api/')) return res.status(404).json({ error: 'not found' });
+ res.status(404).send('Not found');
+});
+
// Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
(async () => {
let loaded = false;
← 066aa0d /api/facets total now reflects FILTERED list (honors q + aes
·
back to Raffiawalls
·
noopener noreferrer on window.open('_blank') sister-site nav 7d76b99 →