← back to Bestwallpaperplace
stage2: wire bestwallpaperplace onto shared catalog (hand-tailored)
a876dd0c6fbae57e39ed0bdc18666f84d58874af · 2026-05-19 11:06:34 -0700 · Steve Abrams
Files touched
Diff
commit a876dd0c6fbae57e39ed0bdc18666f84d58874af
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Tue May 19 11:06:34 2026 -0700
stage2: wire bestwallpaperplace onto shared catalog (hand-tailored)
---
server.js | 41 +++++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 10 deletions(-)
diff --git a/server.js b/server.js
index 3463297..f7ad506 100644
--- a/server.js
+++ b/server.js
@@ -6,19 +6,21 @@ const express = require('express');
const helmet = require('helmet');
const path = require('path');
const fs = require('fs');
+const catalog = require('../_shared/admin-catalog');
const PORT = process.env.PORT || 9920;
const SITE = 'bestwallpaperplace';
const DW_SHOPIFY = 'https://designerwallcoverings.com';
-let DATA_RAW;
+// Resolve slug from site.config.json (NOT dir name) — fall back to dir name.
+let siteCfg = {};
try {
- DATA_RAW = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'products.json'), 'utf8'));
- if (!Array.isArray(DATA_RAW)) throw new Error('products.json must be an array');
+ siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.json'), 'utf8'));
} catch (e) {
- console.error(`[${SITE}] FATAL: could not load products.json — ${e.message}`);
- DATA_RAW = [];
+ console.error(`[${SITE}] could not read site.config.json — ${e.message}`);
}
+const SITE_SLUG = siteCfg.slug || SITE;
+const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
function isJunk(p) {
if (!p.image_url || !p.image_url.trim()) return true;
@@ -30,8 +32,9 @@ function isJunk(p) {
return false;
}
-const PRODUCTS = DATA_RAW.filter(p => !isJunk(p));
-console.log(`[${SITE}] loaded ${DATA_RAW.length}, kept ${PRODUCTS.length}`);
+// Catalog now lives in dw_unified.microsite_products — loaded async at startup
+// (see bottom of file). Falls back to data/products.json if PG is down.
+let PRODUCTS = [];
const COLOR_RANK = {
black:0,gray:1,grey:1,silver:2,white:3,ivory:4,cream:5,beige:6,brown:7,tan:8,khaki:9,copper:10,
@@ -170,6 +173,24 @@ app.get('/sitemap.xml', (req, res) => {
res.type('application/xml').send(xml);
});
-app.listen(PORT, '127.0.0.1', () => {
- console.log(`[${SITE}] listening on http://127.0.0.1:${PORT}`);
-});
+// Admin catalog CRUD — /admin/catalog (basic-auth) + /api/admin/* REST.
+catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
+
+// Load the catalog from dw_unified, then start listening. PG down → JSON fallback.
+(async () => {
+ try {
+ const rows = await catalog.getProducts(SITE_SLUG);
+ PRODUCTS = rows.filter(p => !isJunk(p));
+ console.log(`[${SITE}] loaded ${rows.length} from dw_unified, kept ${PRODUCTS.length}`);
+ } catch (e) {
+ console.error(`[${SITE}] PG catalog load failed (${e.message}) — falling back to data/products.json`);
+ try {
+ const raw = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'products.json'), 'utf8'));
+ PRODUCTS = (Array.isArray(raw) ? raw : []).filter(p => !isJunk(p));
+ } catch (_) { PRODUCTS = []; }
+ console.log(`[${SITE}] fallback loaded ${PRODUCTS.length} from products.json`);
+ }
+ app.listen(PORT, '127.0.0.1', () => {
+ console.log(`[${SITE}] listening on http://127.0.0.1:${PORT}`);
+ });
+})();
← 41b7017 Fix dead /about nav link and add noreferrer to external link
·
back to Bestwallpaperplace
·
Phase 2: mobile-ready + tap-to-reveal 2584c91 →