Files
FWS-TEMPLATE-Website-OnePage/tools/tcp-forward.js
T
2026-09-25 07:32:00 +02:00

26 lines
752 B
JavaScript

#!/usr/bin/env node
/* Tiny TCP forwarder: listens on 127.0.0.1:8765 and pipes to 127.0.0.1:8555.
Exists only because the preview browser cannot attach to Docker's
published port process. Ctrl+C to stop. */
const net = require("net");
const LISTEN = 8765;
const TARGET_PORT = 8555;
const TARGET_HOST = "127.0.0.1";
const server = net.createServer((client) => {
const upstream = net.connect(TARGET_PORT, TARGET_HOST);
client.pipe(upstream);
upstream.pipe(client);
const cleanup = () => {
client.destroy();
upstream.destroy();
};
client.on("error", cleanup);
upstream.on("error", cleanup);
});
server.listen(LISTEN, "127.0.0.1", () => {
console.log(`forwarding 127.0.0.1:${LISTEN} -> ${TARGET_HOST}:${TARGET_PORT}`);
});