[object Object]

← back to Hollywood Wallcoverings

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

ff197dfff1b2a5b447cfa522873d655c35b5140d · 2026-05-19 23:54:31 -0700 · Steve Abrams

Files touched

Diff

commit ff197dfff1b2a5b447cfa522873d655c35b5140d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue May 19 23:54:31 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 9760f1e..5c0c9e3 100644
--- a/server.js
+++ b/server.js
@@ -11,7 +11,15 @@ const fs = require('fs');
 
 const PORT = process.env.PORT || 9832;
 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;            // slug ≠ dir name (hollywoodwallcoverings)
 const SITE_RAILS = Array.isArray(siteCfg.rails) ? siteCfg.rails : [];
@@ -829,19 +837,26 @@ app.get('/trade', (_req, res) => {
 app.get('/health', (_req, res) => res.json({ ok: true, products: DATA.length, dropped: DROPPED, types: TYPES }));
 
 // 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, then start listening. PG down → JSON fallback.
+// Load the catalog. When admin is enabled, prefer dw_unified; else static JSON.
 const BIND = process.env.BIND || '127.0.0.1';
 (async () => {
-  try {
-    const rows = await catalog.getProducts(SITE_SLUG);
-    if (!rows.length) throw new Error('0 rows from microsite_products');
-    rebuildCatalog(rows);
-    console.log(`[${__SITE}] loaded ${rows.length} from dw_unified (slug=${SITE_SLUG})`);
-  } 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);
+      if (!rows.length) throw new Error('0 rows from microsite_products');
+      rebuildCatalog(rows);
+      console.log(`[${__SITE}] loaded ${rows.length} from dw_unified (slug=${SITE_SLUG})`);
+      loaded = true;
+    } catch (e) {
+      console.error(`[${__SITE}] PG catalog load failed (${e.message}) — falling back to data/products.json`);
+    }
+  }
+  if (!loaded) {
     rebuildCatalog(loadFromJson());
+    console.log(`[${__SITE}] loaded ${DATA.length} from data/products.json (static mode)`);
   }
   app.listen(PORT, BIND, () => console.log(`Hollywood Wallcoverings on http://${BIND}:${PORT} · ${DATA.length} products`));
 })();

← 6c8e945 add corner-nav.js — universal top-right nav per _shared/corn  ·  back to Hollywood Wallcoverings  ·  rails → top-6 actual catalog vocab (textured/architectural/c b04a2c0 →