[object Object]

← back to Wallsandfabrics

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

8e9fdd59fa934a1c896c59c2fed7e9c7cc27c2b0 · 2026-05-19 23:55:54 -0700 · Steve Abrams

Files touched

Diff

commit 8e9fdd59fa934a1c896c59c2fed7e9c7cc27c2b0
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue May 19 23:55:54 2026 -0700

    make server.js self-contained — gate _shared/admin-catalog behind MICROSITE_ADMIN_ENABLED env flag (kamatera deploy unblock)
---
 server.js | 39 +++++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 12 deletions(-)

diff --git a/server.js b/server.js
index 200a135..09eab29 100644
--- a/server.js
+++ b/server.js
@@ -12,7 +12,15 @@ const PORT = process.env.PORT || 9934;
 const DW_SHOPIFY = 'https://designerwallcoverings.com';
 const __SITE = path.basename(__dirname);
 
-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(`[${__SITE}] 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_SLUG = siteCfg.slug || __SITE;
 const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
@@ -213,7 +221,7 @@ ${urls.map(u => `  <url><loc>https://wallsandfabrics.com${u}</loc><changefreq>we
 });
 
 // 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 });
 
 function loadJsonFallback(reason) {
   console.error(`[${__SITE}] ${reason} — falling back to data/products.json`);
@@ -237,17 +245,24 @@ function loadJsonFallback(reason) {
 //     Once microsite_products.image_url is backfilled for this slug, the PG
 //     path takes over automatically with no code change.
 (async () => {
-  try {
-    const rows = await catalog.getProducts(SITE_SLUG);
-    if (!rows.length) throw new Error('microsite_products returned 0 rows');
-    buildCatalog(rows);
-    if (!PRODUCTS.length) {
-      loadJsonFallback(`PG returned ${rows.length} rows but the surface model kept 0 (no image_url in microsite_products)`);
-    } else {
-      console.log(`[${__SITE}] catalog source: dw_unified.microsite_products (${rows.length} rows)`);
+  let loaded = false;
+  if (catalog) {
+    try {
+      const rows = await catalog.getProducts(SITE_SLUG);
+      if (!rows.length) throw new Error('microsite_products returned 0 rows');
+      buildCatalog(rows);
+      if (!PRODUCTS.length) {
+        loadJsonFallback(`PG returned ${rows.length} rows but the surface model kept 0 (no image_url in microsite_products)`);
+      } else {
+        console.log(`[${__SITE}] catalog source: dw_unified.microsite_products (${rows.length} rows)`);
+      }
+      loaded = true;
+    } catch (e) {
+      loadJsonFallback(`PG catalog load failed (${e.message})`);
     }
-  } catch (e) {
-    loadJsonFallback(`PG catalog load failed (${e.message})`);
+  }
+  if (!loaded) {
+    loadJsonFallback('admin disabled — static mode');
   }
   app.listen(PORT, '127.0.0.1', () => {
     console.log(`[${__SITE}] listening on http://127.0.0.1:${PORT}`);

← 82b7840 add rel=noreferrer to external product card links  ·  back to Wallsandfabrics  ·  add: pre-stage Meta Pixel snippet (placeholder; flip via _dw 272d2be →