← back to Jutewallpaper
/api/facets now drill-down counts over the active filtered set via shared filterProducts() (was counting whole niche catalog regardless of q/aesthetic/vendor; /api/products reuses helper) + 301 redirect legacy /*.html -> clean URLs (before express.static) + 404-guard for stray .bak/.pre-*/.orig backup files
c6b56a275dc48e6f196d5cf8a241f1fdb528d031 · 2026-06-01 07:34:11 -0700 · Steve Abrams
Files touched
Diff
commit c6b56a275dc48e6f196d5cf8a241f1fdb528d031
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Mon Jun 1 07:34:11 2026 -0700
/api/facets now drill-down counts over the active filtered set via shared filterProducts() (was counting whole niche catalog regardless of q/aesthetic/vendor; /api/products reuses helper) + 301 redirect legacy /*.html -> clean URLs (before express.static) + 404-guard for stray .bak/.pre-*/.orig backup files
---
server.js | 46 ++++++++++++++++++++++++++++++++++++++--------
1 file changed, 38 insertions(+), 8 deletions(-)
diff --git a/server.js b/server.js
index 435d16f..50a6e65 100644
--- a/server.js
+++ b/server.js
@@ -147,6 +147,22 @@ app.use(require('../_shared/api-vendor-redact'));
require('./_universal-contact')(app, { siteName: "Jute Wallpaper", zdColor: "#c89858", zdPosition: 'right' });
require('./_universal-auth')(app, { siteName: "jutewallpaper" });
+// 404-guard: never let editor/backup files leak (they shouldn't be deployed,
+// but be defensive so a stray .bak/.pre-*/.orig returns 404, not file contents).
+app.use((req, res, next) => {
+ if (/\.(bak|pre-[^/]*|orig|swp|tmp)(\.[^/]*)?$/i.test(req.path) || /\.bak(\.|$)/i.test(req.path)) {
+ return res.status(404).send('Not found');
+ }
+ next();
+});
+
+// Clean-URL canonicalization: 301 legacy /*.html -> extension-less form
+// (must run before express.static so the .html files aren't served raw).
+app.get(/^\/(care|history|sourcing|trade|vocabulary|index)\.html$/, (req, res) => {
+ const base = req.params[0];
+ res.redirect(301, base === 'index' ? '/' : `/${base}`);
+});
+
app.use(express.static(path.join(__dirname, 'public')));
// Clean-URL routes for static content pages (no .html extension).
@@ -163,15 +179,25 @@ for (const [route, file] of Object.entries(PAGE_ROUTES)) {
app.get(route, (req, res) => res.sendFile(path.join(__dirname, 'public', file)));
}
-app.get('/api/products', (req, res) => {
- const { q, aesthetic, vendor, page = 1, limit = 24, sort = 'newest'} = req.query;
+// Shared filter — applied by both /api/products and /api/facets so facet
+// counts reflect the actual FILTERED result set (drill-down), not the whole
+// niche catalog. `skip` lets each facet dimension count against the OTHER
+// active filters (a facet shouldn't filter itself).
+function filterProducts(query, skip) {
+ const { q, aesthetic, vendor } = query || {};
let list = PRODUCTS_NICHE;
- if (q) {
- const needle = q.toLowerCase();
+ if (q && skip !== 'q') {
+ const needle = String(q).toLowerCase();
list = list.filter(p => (p.title || '').toLowerCase().includes(needle) || (p.tags || []).some(t => t.toLowerCase().includes(needle)));
}
- if (aesthetic && aesthetic !== 'all') list = list.filter(p => p.aesthetic === aesthetic);
- if (vendor && vendor !== 'all') list = list.filter(p => p.vendor === vendor);
+ if (aesthetic && aesthetic !== 'all' && skip !== 'aesthetic') list = list.filter(p => p.aesthetic === aesthetic);
+ if (vendor && vendor !== 'all' && skip !== 'vendor') list = list.filter(p => p.vendor === vendor);
+ return list;
+}
+
+app.get('/api/products', (req, res) => {
+ const { page = 1, limit = 24, sort = 'newest'} = req.query;
+ let list = filterProducts(req.query);
list = sortProducts(list, sort);
const total = list.length;
const pageNum = Math.max(1, parseInt(page) || 1);
@@ -192,11 +218,15 @@ app.get('/api/sliders', (req, res) => {
app.get('/api/facets', (req, res) => {
const aesthetics = {}; const vendors = {};
- for (const p of PRODUCTS_NICHE) {
+ // Each dimension counts over the set filtered by the OTHER active facets
+ // (drill-down); total reflects the fully-filtered result set.
+ for (const p of filterProducts(req.query, 'aesthetic')) {
aesthetics[p.aesthetic] = (aesthetics[p.aesthetic] || 0) + 1;
+ }
+ for (const p of filterProducts(req.query, 'vendor')) {
vendors[p.vendor] = (vendors[p.vendor] || 0) + 1;
}
- res.json({ aesthetics, vendors, total: PRODUCTS_NICHE.length });
+ res.json({ aesthetics, vendors, total: filterProducts(req.query).length });
});
app.get('/api/health', (req, res) => res.json({ status: 'ok', count: PRODUCTS_NICHE.length, dropped: DROPPED }));
← 489d715 remove leaked backup file from public/ and fix .gitignore to
·
back to Jutewallpaper
·
add noopener,noreferrer to sister-site constellation window. 8caa5f0 →