diff --git a/Dockerfile b/Dockerfile index badf2f5..a71a364 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,4 +28,4 @@ WORKDIR /app COPY package*.json ./ RUN npm install && npm install -g playwright && playwright install chromium COPY . . -CMD ["npx", "playwright", "test"] +CMD ["bash", "-lc", "node server/wizard-proxy.mjs & npx playwright test"] diff --git a/server/wizard-proxy.mjs b/server/wizard-proxy.mjs new file mode 100644 index 0000000..4ee1dfe --- /dev/null +++ b/server/wizard-proxy.mjs @@ -0,0 +1,32 @@ +import http from 'http' + +const listenPort = Number(process.env.WIZARD_PORT || 8080) +const targetHost = process.env.WIZARD_HOST || 'wizard' +const targetPort = Number(process.env.WIZARD_PORT || 8080) + +http + .createServer((req, res) => { + const proxyReq = http.request( + { + hostname: targetHost, + port: targetPort, + path: req.url, + method: req.method, + headers: req.headers, + }, + (proxyRes) => { + res.writeHead(proxyRes.statusCode || 502, proxyRes.headers) + proxyRes.pipe(res) + } + ) + + proxyReq.on('error', (err) => { + res.statusCode = 502 + res.end(`Bad gateway: ${err.message}`) + }) + + req.pipe(proxyReq) + }) + .listen(listenPort, '127.0.0.1', () => { + console.log(`wizard proxy listening on 127.0.0.1:${listenPort} -> ${targetHost}:${targetPort}`) + })