[object Object]

← back to Customdigitalmurals

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

24e237ed7fd0cac7b0b54c7f28fb575c3e27fb75 · 2026-05-21 20:06:50 -0700 · Steve Abrams

Files touched

Diff

commit 24e237ed7fd0cac7b0b54c7f28fb575c3e27fb75
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu May 21 20:06:50 2026 -0700

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

diff --git a/server.js b/server.js
index 3d1aa93..028e54c 100644
--- a/server.js
+++ b/server.js
@@ -15,7 +15,15 @@ const PORT = process.env.PORT || 9896;
 const DATA_FILE = path.join(__dirname, 'data', 'products.json');
 
 // Shared catalog module — read-path from dw_unified.microsite_products + admin CRUD.
-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(`[customdigitalmurals] 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 || path.basename(__dirname);
 const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
@@ -120,7 +128,7 @@ 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 });
 
 // Merge a PG microsite_products row with the rich static snapshot (by handle),
 // so the storefront still has images[], price and body_html the migration dropped.
@@ -140,16 +148,23 @@ function enrich(row) {
   };
 }
 
-// Load the catalog from dw_unified, then start listening. PG down → JSON snapshot.
+// Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
 (async () => {
-  try {
-    const rows = await catalog.getProducts(SITE_SLUG);
-    if (!rows.length) throw new Error('microsite_products returned 0 rows');
-    ALL = rows.map(enrich);
-    console.log(`[${SITE_SLUG}] loaded ${ALL.length} products from dw_unified`);
-  } catch (e) {
-    console.error(`[${SITE_SLUG}] PG catalog load failed (${e.message}) — using data/products.json`);
+  let loaded = false;
+  if (catalog) {
+    try {
+      const rows = await catalog.getProducts(SITE_SLUG);
+      if (!rows.length) throw new Error('microsite_products returned 0 rows');
+      ALL = rows.map(enrich);
+      console.log(`[${SITE_SLUG}] loaded ${ALL.length} products from dw_unified`);
+      loaded = true;
+    } catch (e) {
+      console.error(`[${SITE_SLUG}] PG catalog load failed (${e.message}) — using data/products.json`);
+    }
+  }
+  if (!loaded) {
     ALL = STATIC;
+    console.log(`[${SITE_SLUG}] loaded ${ALL.length} from data/products.json (static mode)`);
   }
   app.listen(PORT, () => console.log(`customdigitalmurals.com :${PORT} (${ALL.length} products)`));
 })();

← 58bcf6a guard against serving .bak/.pre- snapshot files; widen .giti  ·  back to Customdigitalmurals  ·  retag aesthetic from PG: 3663 rows updated 27a4699 →