1// Probe server for the #1334 host-reach regression test. Plain node, no
2// deps. `/env` reports the env the container actually received (so the test
3// can assert the loopback rewrite); `/probe` fetches TARGET_URL from INSIDE
4// the container and reports what came back — the proof that a value written
5// as `http://localhost:…` still reaches the developer machine.
6//
7// NOTE: this file is force-added past the repo's `*.js` ignore rule — the
8// docker build COPYs it, so a checkout without it fails the container boot.
9const http = require("node:http");
10
11const server = http.createServer(async (req, res) => {
12 res.setHeader("content-type", "application/json");
13 if (req.url === "/env") {
14 res.end(
15 JSON.stringify({
16 TARGET_URL: process.env.TARGET_URL,
17 PPG_URL: process.env.PPG_URL,
18 NEON_URL: process.env.NEON_URL,
19 PLANETSCALE_PG_URL: process.env.PLANETSCALE_PG_URL,
20 PLANETSCALE_MYSQL_URL: process.env.PLANETSCALE_MYSQL_URL,
21 }),
22 );
23 return;
24 }
25 if (req.url === "/probe") {
26 try {
27 const response = await fetch(process.env.TARGET_URL);
28 const body = await response.text();
29 res.end(JSON.stringify({ status: response.status, body }));
30 } catch (error) {
31 res.end(JSON.stringify({ error: String(error) }));
32 }
33 return;
34 }
35 res.end(JSON.stringify({ ok: true }));
36});
37
38server.listen(8080, () => {
39 console.log("hostreach probe server listening on 8080");
40});