[object Object]

← back to Goldleafwallpaper

Fix sample/inquiry forms: send George X-Send-Approval token (external-send guard) via env; load .env

57e5e4e16bc76057561bdf142f478b1c17f367e3 · 2026-07-14 13:06:39 -0700 · Steve

Files touched

Diff

commit 57e5e4e16bc76057561bdf142f478b1c17f367e3
Author: Steve <steve@designerwallcoverings.com>
Date:   Tue Jul 14 13:06:39 2026 -0700

    Fix sample/inquiry forms: send George X-Send-Approval token (external-send guard) via env; load .env
---
 server.js | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/server.js b/server.js
index 86a9255..868e38c 100644
--- a/server.js
+++ b/server.js
@@ -1,3 +1,7 @@
+// Load .env if present (holds GEORGE_EXTERNAL_SEND_TOKEN for the sample/inquiry
+// forms). Wrapped so the site still boots if dotenv isn't installed.
+try { require('dotenv').config({ path: require('path').join(__dirname, '.env') }); } catch (e) {}
+
 const express = require('express');
 const path = require('path');
 const http = require('http');
@@ -12,6 +16,20 @@ app.use(express.json());
 const GEORGE_PORT = parseInt(process.env.GEORGE_PORT || '9850', 10);
 const GEORGE_AUTH = process.env.GEORGE_AUTH ||
   ('Basic ' + Buffer.from('admin:' + (process.env.GEORGE_BASIC_AUTH_PASS || '')).toString('base64'));
+// George fail-closes external email (info@goldleafwallpaper.com is external to
+// George's own Gmail account) and requires the human-approval token in an
+// X-Send-Approval header, else the send is blocked with a 502. Without this the
+// sample-request + inquiry forms silently drop every customer submission.
+const GEORGE_APPROVAL = process.env.GEORGE_EXTERNAL_SEND_TOKEN || '';
+const georgeHeaders = (data) => {
+  const h = {
+    'Content-Type': 'application/json',
+    'Content-Length': Buffer.byteLength(data),
+    'Authorization': GEORGE_AUTH,
+  };
+  if (GEORGE_APPROVAL) h['X-Send-Approval'] = GEORGE_APPROVAL;
+  return h;
+};
 const SAMPLE_RECIPIENT = process.env.SAMPLE_RECIPIENT || 'info@goldleafwallpaper.com';
 const INQUIRY_RECIPIENT = process.env.INQUIRY_RECIPIENT || 'info@goldleafwallpaper.com';
 
@@ -61,11 +79,7 @@ app.post('/api/send-sample-request', (req, res) => {
   const upstream = http.request({
     hostname: '127.0.0.1', port: GEORGE_PORT, path: '/api/send',
     method: 'POST', timeout: 15000,
-    headers: {
-      'Content-Type': 'application/json',
-      'Content-Length': Buffer.byteLength(data),
-      'Authorization': GEORGE_AUTH
-    }
+    headers: georgeHeaders(data)
   }, r => {
     let chunks = '';
     r.on('data', c => chunks += c);
@@ -118,11 +132,7 @@ app.post('/api/send-inquiry', (req, res) => {
   const upstream = http.request({
     hostname: '127.0.0.1', port: GEORGE_PORT, path: '/api/send',
     method: 'POST', timeout: 15000,
-    headers: {
-      'Content-Type': 'application/json',
-      'Content-Length': Buffer.byteLength(data),
-      'Authorization': GEORGE_AUTH
-    }
+    headers: georgeHeaders(data)
   }, r => {
     let chunks = '';
     r.on('data', c => chunks += c);

← 1fd1307 auto-save: 2026-07-14T13:01:14 (2 files) — scripts/rebuild-a  ·  back to Goldleafwallpaper  ·  chore: lint, refactor, v1.1.0 (session close) 05fb8b5 →