[object Object]

← back to Bleachresistantfabrics

make server.js self-contained — gate _shared/admin-catalog behind MICROSITE_ADMIN_ENABLED env flag (kamatera deploy unblock)

df472d14aa1cfc099ed102767a1f9178c4a7149a · 2026-05-21 20:04:43 -0700 · Steve Abrams

Files touched

Diff

commit df472d14aa1cfc099ed102767a1f9178c4a7149a
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu May 21 20:04:43 2026 -0700

    make server.js self-contained — gate _shared/admin-catalog behind MICROSITE_ADMIN_ENABLED env flag (kamatera deploy unblock)
---
 server.js        | 35 ++++++++++++++++++++++++-----------
 site.config.json | 12 ++++++------
 2 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/server.js b/server.js
index 483f596..3db2c0e 100644
--- a/server.js
+++ b/server.js
@@ -13,7 +13,15 @@ const helmet = require('helmet');
 const path = require('path');
 const fs = require('fs');
 
-const catalog = require('../_shared/admin-catalog');
+// Admin catalog (PG-backed) is opt-in via MICROSITE_ADMIN_ENABLED=true. Prod
+// stays static-only (data/products.json) so Kamatera doesn't need `pg` or the
+// _shared/ tree. Dev (Mac2) flips the flag on to use dw_unified + /admin/catalog.
+const ADMIN_ENABLED = process.env.MICROSITE_ADMIN_ENABLED === 'true';
+let catalog = null;
+if (ADMIN_ENABLED) {
+  try { catalog = require('../_shared/admin-catalog'); }
+  catch (e) { console.error(`[bleachresistantfabrics] admin-catalog unavailable (${e.message}) — falling back to static JSON`); }
+}
 const siteCfg = JSON.parse(fs.readFileSync(path.join(__dirname, 'site.config.json'), 'utf8'));
 const SITE = 'bleachresistantfabrics';
 const SITE_SLUG = siteCfg.slug || SITE;          // do not assume slug === dir name
@@ -163,20 +171,25 @@ app.get('/sitemap.xml', (req, res) => {
 });
 
 // Admin catalog CRUD — /admin/catalog (basic-auth) + /api/admin/* REST.
-catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
+if (catalog) catalog.mount(app, { siteSlug: SITE_SLUG, rails: SITE_RAILS });
 
-// Load the catalog from dw_unified, run it through the niche pipeline, then
-// start listening. PG down → fall back to the bundled data/products.json.
+// Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
 (async () => {
-  try {
-    const rows = await catalog.getProducts(SITE_SLUG);
-    PRODUCTS = pipeline(rows);
-    console.log(`[${SITE}] loaded ${rows.length} from dw_unified → niche ${PRODUCTS.length}`);
-  } catch (e) {
-    console.error(`[${SITE}] PG catalog load failed (${e.message}) — falling back to data/products.json`);
+  let loaded = false;
+  if (catalog) {
+    try {
+      const rows = await catalog.getProducts(SITE_SLUG);
+      PRODUCTS = pipeline(rows);
+      console.log(`[${SITE}] loaded ${rows.length} from dw_unified → niche ${PRODUCTS.length}`);
+      loaded = true;
+    } catch (e) {
+      console.error(`[${SITE}] PG catalog load failed (${e.message}) — falling back to data/products.json`);
+    }
+  }
+  if (!loaded) {
     const raw = loadStaticRaw();
     PRODUCTS = pipeline(raw);
-    console.log(`[${SITE}] loaded ${raw.length} from static JSON → niche ${PRODUCTS.length}`);
+    console.log(`[${SITE}] loaded ${raw.length} from data/products.json (static mode) → niche ${PRODUCTS.length}`);
   }
   app.listen(PORT, '127.0.0.1', () => {
     console.log(`[${SITE}] listening on http://127.0.0.1:${PORT}`);
diff --git a/site.config.json b/site.config.json
index 3c81a37..b8e6e68 100644
--- a/site.config.json
+++ b/site.config.json
@@ -12,12 +12,12 @@
     "accent": "#3FB6BB"
   },
   "rails": [
-    "crypton",
-    "vinyl-coated",
-    "performance",
-    "healthcare",
-    "moisture-barrier",
-    "antimicrobial"
+    "textured",
+    "contemporary",
+    "beige",
+    "traditional",
+    "white",
+    "gray"
   ],
   "port": 9921
 }

← 9b4bf07 add: pre-stage Meta Pixel snippet (placeholder; flip via _dw  ·  back to Bleachresistantfabrics  ·  retag aesthetic from PG: 598 rows updated 965b78e →