[object Object]

← back to Carmelwallpapers

Wire vendor-neutral image-proxy into carmel storefront (no vendor filenames in customer output)

fd64d514106563f7764c68e754d402b9b5ff5fcc · 2026-06-03 14:34:22 -0700 · Steve Abrams

Files touched

Diff

commit fd64d514106563f7764c68e754d402b9b5ff5fcc
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Wed Jun 3 14:34:22 2026 -0700

    Wire vendor-neutral image-proxy into carmel storefront (no vendor filenames in customer output)
---
 server.js | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/server.js b/server.js
index d13add5..563e3c0 100644
--- a/server.js
+++ b/server.js
@@ -3,6 +3,8 @@ try { require('dotenv').config({ path: require('path').join(__dirname, '.env') }
 const express = require('express');
 const fs = require('fs');
 const path = require('path');
+const { createImgProxy } = require('../_shared/image-proxy');
+const IMGP = createImgProxy();   // vendor-neutral /img/<token> image proxy
 
 const PORT = process.env.PORT || 9832;
 const DATA_PATH = path.join(__dirname, 'data', 'products.json');
@@ -175,6 +177,10 @@ function applyProducts(raw) {
   for (const p of PRODUCTS) {
     AESTHETICS[p.aesthetic] = (AESTHETICS[p.aesthetic] || 0) + 1;
   }
+  // (Re)build the /img token->CDN map whenever products (re)load — covers the
+  // admin-catalog runtime reload path, not just boot. Map is additive (set), so
+  // re-registering is idempotent and never strands a previously-issued token.
+  IMGP.registerAll(PRODUCTS);
 }
 
 function loadFromJson() {
@@ -220,6 +226,10 @@ app.use(require('../_shared/api-vendor-redact'));
 
 app.use(express.static(path.join(__dirname, 'public')));
 
+// Vendor-neutral image proxy: GET /img/<token> streams the real CDN bytes so
+// the 3rd-party vendor filename never reaches the client. (see _shared/image-proxy.js)
+IMGP.mount(app);
+
 // ── HTML helpers ─────────────────────────────────────────────────────────────
 const HTML_HEAD = (title, desc) => `<!DOCTYPE html>
 <html lang="en">
@@ -376,7 +386,8 @@ app.get('/api/products', (req, res) => {
   const pageNum = Math.max(1, parseInt(page)||1);
   const lim = Math.min(60, parseInt(limit)||24);
   const start = (pageNum-1)*lim;
-  res.json({ total, page: pageNum, limit: lim, pages: Math.ceil(total/lim), sort, items: list.slice(start, start+lim) });
+  const items = list.slice(start, start+lim).map(p => ({ ...IMGP.scrubProduct(p), slug: p.slug || redactVendorSlug(p.handle) }));
+  res.json({ total, page: pageNum, limit: lim, pages: Math.ceil(total/lim), sort, items });
 });
 
 // ── API: sliders ─────────────────────────────────────────────────────────────
@@ -385,7 +396,7 @@ app.get('/api/sliders', (req, res) => {
   const out = [];
   for (const a of RAIL_ORDER) {
     const items = PRODUCTS.filter(p => p.aesthetic === a).slice(0, 12);
-    if (items.length >= 4) out.push({ aesthetic: a, items });
+    if (items.length >= 4) out.push({ aesthetic: a, items: items.map(IMGP.scrubProduct) });
   }
   res.json({ rails: out });
 });
@@ -418,7 +429,7 @@ app.get('/p/:handle', (req, res) => {
   const title = `${p.title} — Carmel Wallpapers | Free Memo Samples, Trade Service`;
   const desc = `${p.title} by Designer Wallcoverings. Order a free memo sample. Coastal California's curated wallpaper source — expert trade service, hand-holding from Carmel to Pebble Beach.`;
 
-  const imgs = (p.images||[p.image_url]).filter(Boolean);
+  const imgs = (p.images||[p.image_url]).filter(Boolean).map(IMGP.proxyImg);
   const imgHtml = imgs.map((src,i) =>
     `<img src="${src}" alt="${p.title}${i?` view ${i+1}`:''}${i===0?' (main)':''}" loading="${i===0?'eager':'lazy'}" class="detail-img${i===0?' detail-img--main':''}">`
   ).join('\n');
@@ -761,5 +772,7 @@ if (catalog) catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
 // ── Startup: load catalog from PG, then listen ───────────────────────────────
 (async () => {
   await loadData();
+  IMGP.registerAll(PRODUCTS);   // build the /img token->CDN map for every product image (idempotent; applyProducts also registers)
+  console.log(`[carmel] image-proxy map: ${IMGP.size()} urls`);
   app.listen(PORT, () => console.log(`carmelwallpapers listening on :${PORT}`));
 })();

← e802dce Unique clean image hero (fleet hero dedup 2026-06-01)  ·  back to Carmelwallpapers  ·  Scrub residual vendor names from products.json (title/vendor 06b4f59 →