Skip to content

Commit 5bf8e7f

Browse files
committed
Fix proxy server network binding to expose ports on all interfaces
- Change LISTEN_HOST from 'localhost' to '0.0.0.0' to bind proxy server to all network interfaces - This allows the proxy server to be accessible from all network interfaces instead of just localhost
1 parent 470161e commit 5bf8e7f

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

worker/proxy_server.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const fs = require("fs");
1212
const path = require("path");
1313

1414
/* ──────────────────────────── worker code ─────────────────────────────── */
15-
const LISTEN_HOST = "localhost";
15+
const LISTEN_HOST = "0.0.0.0";
1616
const LISTEN_PORT = workerData.port;
1717
let rememberedOrigin = null; // e.g. "http://localhost:5173"
1818

@@ -56,12 +56,12 @@ try {
5656
}
5757

5858
try {
59-
const dyadShimPath = path.join(__dirname, "SFARPakim.js");
59+
const dyadShimPath = path.join(__dirname, "dyad-shim.js");
6060
dyadShimContent = fs.readFileSync(dyadShimPath, "utf-8");
61-
parentPort?.postMessage("[proxy-worker] SFARPakim.js loaded.");
61+
parentPort?.postMessage("[proxy-worker] dyad-shim.js loaded.");
6262
} catch (error) {
6363
parentPort?.postMessage(
64-
`[proxy-worker] Failed to read SFARPakim.js: ${error.message}`,
64+
`[proxy-worker] Failed to read dyad-shim.js: ${error.message}`,
6565
);
6666
}
6767

@@ -149,10 +149,14 @@ function buildTargetURL(clientReq) {
149149
/* ----------------------------------------------------------------------- */
150150

151151
const server = http.createServer((clientReq, clientRes) => {
152+
parentPort?.postMessage(`[proxy] Request: ${clientReq.method} ${clientReq.url}`);
153+
152154
let target;
153155
try {
154156
target = buildTargetURL(clientReq);
157+
parentPort?.postMessage(`[proxy] Forwarding to: ${target.href}`);
155158
} catch (err) {
159+
parentPort?.postMessage(`[proxy] Error building target URL: ${err.message}`);
156160
clientRes.writeHead(400, { "content-type": "text/plain" });
157161
return void clientRes.end("Bad request: " + err.message);
158162
}
@@ -189,6 +193,8 @@ const server = http.createServer((clientReq, clientRes) => {
189193
};
190194

191195
const upReq = lib.request(upOpts, (upRes) => {
196+
parentPort?.postMessage(`[proxy] Upstream response: ${upRes.statusCode} for ${target.href}`);
197+
192198
const inject = needsInjection(target.pathname);
193199

194200
if (!inject) {
@@ -215,6 +221,7 @@ const server = http.createServer((clientReq, clientRes) => {
215221
clientRes.writeHead(upRes.statusCode, hdrs);
216222
clientRes.end(patched);
217223
} catch (e) {
224+
parentPort?.postMessage(`[proxy] Injection failed: ${e.message}`);
218225
clientRes.writeHead(500, { "content-type": "text/plain" });
219226
clientRes.end("Injection failed: " + e.message);
220227
}
@@ -223,6 +230,7 @@ const server = http.createServer((clientReq, clientRes) => {
223230

224231
clientReq.pipe(upReq);
225232
upReq.on("error", (e) => {
233+
parentPort?.postMessage(`[proxy] Upstream error: ${e.message} for ${target?.href || 'unknown'}`);
226234
clientRes.writeHead(502, { "content-type": "text/plain" });
227235
clientRes.end("Upstream error: " + e.message);
228236
});

0 commit comments

Comments
 (0)