[object Object]

← back to Textilewallpaper

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

71a5bcc2f2fbce045c8ac04ab390f9ee9b2e3378 · 2026-05-19 23:52:35 -0700 · Steve Abrams

Files touched

Diff

commit 71a5bcc2f2fbce045c8ac04ab390f9ee9b2e3378
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Tue May 19 23:52:35 2026 -0700

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

diff --git a/server.js b/server.js
index 539e978..cfb3427 100644
--- a/server.js
+++ b/server.js
@@ -10,7 +10,15 @@ const fs = require('fs');
 const PORT = process.env.PORT || 9869;
 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 : [];
@@ -129,7 +137,23 @@ function sortProducts(list, mode) {
 
 
 app.use(express.json({ limit: "256kb" }));
-const cfg = require('../_shared/site-config').load(__dirname);
+// Site config — prefer _shared/site-config (canonical) but fall back to an
+// inline minimal loader so this server.js is self-contained on Kamatera.
+let cfg;
+try {
+  cfg = require('../_shared/site-config').load(__dirname);
+} catch (_) {
+  const domain = siteCfg.domain || `${SITE_SLUG}.com`;
+  cfg = Object.freeze({
+    slug: SITE_SLUG, siteName: siteCfg.siteName || SITE_SLUG,
+    domain, siteEmail: siteCfg.siteEmail || `info@${domain}`,
+    contact: { siteName: siteCfg.siteName || SITE_SLUG, domain,
+               siteEmail: siteCfg.siteEmail || `info@${domain}`,
+               zdColor: (siteCfg.theme && siteCfg.theme.accent) || '#C9A14B',
+               zdPosition: siteCfg.zdPosition || 'right' },
+    auth: { siteName: SITE_SLUG },
+  });
+}
 require("./_universal-contact")(app, cfg.contact);
 require("./_universal-auth")(app, cfg.auth);
 // Block stale snapshot files in public/ from being served as static content.
@@ -205,20 +229,27 @@ ${urls.map(u => `  <url><loc>https://textilewallpaper.com${u}</loc><changefreq>w
 });
 
 // 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.
 (async () => {
-  try {
-    const rows = await catalog.getProducts(SITE_SLUG);
-    PRODUCTS = rows.filter(p => !isJunk(p));
-    DROPPED = rows.length - PRODUCTS.length;
-    console.log(`[${__SITE}] loaded ${rows.length} from dw_unified, kept ${PRODUCTS.length}, dropped ${DROPPED}`);
-  } 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 = rows.filter(p => !isJunk(p));
+      DROPPED = rows.length - PRODUCTS.length;
+      console.log(`[${__SITE}] loaded ${rows.length} from dw_unified, kept ${PRODUCTS.length}, dropped ${DROPPED}`);
+      loaded = true;
+    } catch (e) {
+      console.error(`[${__SITE}] PG catalog load failed (${e.message}) — falling back to data/products.json`);
+    }
+  }
+  if (!loaded) {
     try {
       const raw = JSON.parse(fs.readFileSync(path.join(__dirname, 'data', 'products.json'), 'utf8'));
       PRODUCTS = (Array.isArray(raw) ? raw : []).filter(p => !isJunk(p));
+      console.log(`[${__SITE}] loaded ${PRODUCTS.length} from data/products.json (static mode)`);
     } catch (_) { PRODUCTS = []; }
   }
   PRODUCTS_NICHE = PRODUCTS.filter(nicheFit);

← 85b95f6 Phase 2b: harden .card .pat against long-token title clippin  ·  back to Textilewallpaper  ·  add: pre-stage Meta Pixel snippet (placeholder; flip via _dw 1eed603 →