[object Object]

← back to Bestwallpaperplace

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

65d936345bcd87cb25312e8806ade7e64d6f6391 · 2026-05-21 20:04:01 -0700 · Steve Abrams

Files touched

Diff

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

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

diff --git a/server.js b/server.js
index f7ad506..2c2718d 100644
--- a/server.js
+++ b/server.js
@@ -6,7 +6,15 @@ const express = require('express');
 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(`[bestwallpaperplace] admin-catalog unavailable (${e.message}) — falling back to static JSON`); }
+}
 
 const PORT = process.env.PORT || 9920;
 const SITE = 'bestwallpaperplace';
@@ -174,21 +182,27 @@ 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, 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));
-    console.log(`[${SITE}] loaded ${rows.length} from dw_unified, kept ${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 = rows.filter(p => !isJunk(p));
+      console.log(`[${SITE}] loaded ${rows.length} from dw_unified, kept ${PRODUCTS.length}`);
+      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 = []; }
-    console.log(`[${SITE}] fallback loaded ${PRODUCTS.length} from products.json`);
   }
   app.listen(PORT, '127.0.0.1', () => {
     console.log(`[${SITE}] listening on http://127.0.0.1:${PORT}`);

← 8d0f515 add: pre-stage Meta Pixel snippet (placeholder; flip via _dw  ·  back to Bestwallpaperplace  ·  retag aesthetic from PG: 600 rows updated 960ec72 →