← back to Marketing Command Center
scripts/verify-proxy.js
26 lines
// Verification harness: serve LOCAL (fixed) /app.js, proxy everything else to the
// live MCC with Basic auth injected. Lets us test the one changed file vs real data.
const http = require('http');
const https = require('https');
const fs = require('fs');
const path = require('path');
const UP = 'marketing.designerwallcoverings.com';
const AUTH = 'Basic ' + Buffer.from('admin:DW2024!').toString('base64');
const APPJS = fs.readFileSync(path.join(__dirname, '..', 'public', 'app.js'), 'utf8');
const server = http.createServer((req, res) => {
if (req.url === '/app.js') {
res.writeHead(200, { 'Content-Type': 'application/javascript' });
return res.end(APPJS);
}
const opts = { host: UP, path: req.url, method: req.method, headers: { ...req.headers, host: UP, authorization: AUTH } };
const up = https.request(opts, r => {
// strip upstream Set-Cookie 'Secure' so it works over local http (not needed but tidy)
res.writeHead(r.statusCode, r.headers);
r.pipe(res);
});
up.on('error', e => { res.writeHead(502); res.end('proxy err ' + e.message); });
req.pipe(up);
});
server.listen(0, () => console.log('PROXY_PORT=' + server.address().port));