From ca4e52336af0f57795442bd2770fc790c7d97ec2 Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 16 Jun 2026 07:55:56 -0400 Subject: [PATCH] Proxy /photos and /uploads through main-site to gallery backend NPMplus routes beachpartyballoons.com directly to main-site Express, bypassing Docker nginx. Adding proxy routes here ensures same-origin image URLs, eliminating OpaqueResponseBlocking in the browser. Co-Authored-By: Claude Sonnet 4.6 --- main-site/server.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main-site/server.js b/main-site/server.js index c2f1612..75ef478 100644 --- a/main-site/server.js +++ b/main-site/server.js @@ -250,6 +250,29 @@ apiRouter.post('/contact', upload.array('photos', 3), async (req, res) => { // Mount the API router under the /api path app.use('/api', apiRouter); +// --- Gallery backend proxy (/photos and /uploads → gallery-backend container) --- +const http = require('http'); +const GALLERY_HOST = process.env.GALLERY_BACKEND_HOST || 'gallery-backend'; +const GALLERY_PORT = parseInt(process.env.GALLERY_BACKEND_PORT || '5000'); + +function proxyToGallery(req, res) { + const proxy = http.request({ + hostname: GALLERY_HOST, + port: GALLERY_PORT, + path: req.originalUrl, + method: req.method, + headers: { ...req.headers, host: GALLERY_HOST }, + }, (proxyRes) => { + res.writeHead(proxyRes.statusCode, proxyRes.headers); + proxyRes.pipe(res); + }); + proxy.on('error', () => { if (!res.headersSent) res.status(502).end(); }); + req.pipe(proxy); +} + +app.use('/photos', proxyToGallery); +app.use('/uploads', proxyToGallery); + // --- Static Files --- const staticCacheOptions = { maxAge: process.env.NODE_ENV === 'production' ? '30d' : 0,