← back to Chinoiseriewallpaper
make server.js self-contained — gate _shared/admin-catalog behind MICROSITE_ADMIN_ENABLED env flag (kamatera deploy unblock)
f8ab913ec70c50732bc311c16bdc1b88840502b9 · 2026-05-21 20:05:24 -0700 · Steve Abrams
Files touched
Diff
commit f8ab913ec70c50732bc311c16bdc1b88840502b9
Author: Steve Abrams <steve@designerwallcoverings.com>
Date: Thu May 21 20:05:24 2026 -0700
make server.js self-contained — gate _shared/admin-catalog behind MICROSITE_ADMIN_ENABLED env flag (kamatera deploy unblock)
---
server.js | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/server.js b/server.js
index 01f99f9..d8770a4 100644
--- a/server.js
+++ b/server.js
@@ -21,7 +21,15 @@ const fs = require('fs');
const PORT = process.env.PORT || 9853;
const DW_SHOPIFY = 'https://designerwallcoverings.com';
const DOMAIN = 'chinoiseriewallpaper.com';
-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(`[chinoiserie] 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 : [];
@@ -287,19 +295,26 @@ app.get('/', (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_PRE = rows.filter(p => !isJunk(p));
- console.log(`[chinoiserie] loaded ${rows.length} from dw_unified, after strict-chinois filter: ${PRODUCTS_PRE.length}`);
- } catch (e) {
- console.error(`[chinoiserie] 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_PRE = rows.filter(p => !isJunk(p));
+ console.log(`[chinoiserie] loaded ${rows.length} from dw_unified, after strict-chinois filter: ${PRODUCTS_PRE.length}`);
+ loaded = true;
+ } catch (e) {
+ console.error(`[chinoiserie] 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_PRE = (Array.isArray(raw) ? raw : []).filter(p => !isJunk(p));
+ console.log(`[chinoiserie] loaded ${PRODUCTS_PRE.length} from data/products.json (static mode)`);
} catch (_) { PRODUCTS_PRE = []; }
}
app.listen(PORT, '127.0.0.1', () => {
← 3fcbcd6 add: pre-stage Meta Pixel snippet (placeholder; flip via _dw
·
back to Chinoiseriewallpaper
·
retag aesthetic from PG: 1193 rows updated 4901605 →