Skip to content

Running the Proxy Locally

Mike Daley edited this page Mar 9, 2026 · 1 revision

Running the Proxy Locally

The SpectREM Web Spectranet emulation requires a WebSocket-to-UDP/TCP proxy server to bridge the browser's network restrictions. Browsers cannot make raw TCP or UDP connections, so the proxy translates WebSocket frames into real network traffic on behalf of the emulator.

The proxy lives in the proxy/ directory at the root of the repository.


Prerequisites

  • Node.js 18+ (20 recommended)
  • npm (comes with Node.js)

Quick Start

cd proxy
npm install
ALLOWED_ORIGINS=http://localhost:3000 ALLOW_PRIVATE=true node udp-proxy.js

This starts the proxy on ws://localhost:8080 and allows connections from the Vite dev server at http://localhost:3000.


Configuring the Emulator

Once the proxy is running, tell the emulator where to find it:

  1. Open SpectREM Web in your browser (http://localhost:3000)
  2. Enable Spectranet via Dev > Spectranet
  3. Open the Spectranet debug window via View > Spectranet
  4. In the Proxy URL field, enter: ws://localhost:8080
  5. Click Apply

The proxy URL is persisted to localStorage, so you only need to set it once.


Environment Variables

Variable Default Description
PORT 8080 Port the proxy listens on
ALLOWED_ORIGINS (none — required) Comma-separated list of allowed origins. Set to http://localhost:3000 for local dev
ALLOW_PRIVATE false Set to true to allow connections to private/LAN IP addresses (e.g., a TNFS server on your local network)
ALLOWED_PORTS 53,16384,32768 Comma-separated destination port allowlist. Default covers DNS (53) and TNFS (16384, 32768). Set to * to allow all ports
MAX_CONN_PER_IP 4 Max concurrent WebSocket connections per client IP (matches W5100's 4 sockets)
IDLE_TIMEOUT_MS 30000 Close idle connections after this many milliseconds

Example: Connecting to a LAN TNFS Server

If you have a TNFS server running on your local network (e.g., 192.168.1.50:16384), start the proxy with private IPs allowed:

ALLOWED_ORIGINS=http://localhost:3000 ALLOW_PRIVATE=true node udp-proxy.js

Then configure the Spectranet in the emulator to connect to your TNFS server's IP address as usual — the proxy will relay the traffic.


Running with Docker

A Dockerfile is provided for containerised deployment:

cd proxy
docker build -t spectranet-proxy .
docker run -p 8080:8080 \
  -e ALLOWED_ORIGINS=http://localhost:3000 \
  -e ALLOW_PRIVATE=true \
  spectranet-proxy

How It Works

The proxy accepts WebSocket connections with a path that encodes the protocol, destination IP, and port:

ws://localhost:8080/udp/{dest_ip}/{dest_port}   → UDP datagram relay
ws://localhost:8080/tcp/{dest_ip}/{dest_port}   → TCP stream relay

When the emulated Spectranet's W5100 chip issues a CONNECT or SEND command, the JavaScript network manager opens a WebSocket to the proxy at the appropriate path. The proxy then:

  1. For UDP: Creates a UDP socket, forwards each WebSocket message as a UDP datagram, and relays any responses back over the WebSocket
  2. For TCP: Opens a TCP connection to the destination, bidirectionally streams data between the WebSocket and TCP socket

Security

The proxy includes several safeguards:

  • Origin allowlist — only accepts WebSocket upgrades from specified origins
  • Private IP blocking — prevents SSRF by default (disabled with ALLOW_PRIVATE=true)
  • Port allowlist — only relays to explicitly allowed destination ports
  • Per-IP connection limit — prevents resource exhaustion
  • Idle timeout — automatically closes stale connections

Troubleshooting

"Origin not allowed" errors in proxy logs Ensure ALLOWED_ORIGINS includes the exact origin of your dev server (e.g., http://localhost:3000 — note http, not https).

Connections to LAN addresses rejected Set ALLOW_PRIVATE=true when starting the proxy.

Port not allowed errors Add the destination port to ALLOWED_PORTS (e.g., ALLOWED_PORTS=53,16384,32768,80).

Proxy not reachable from the emulator Make sure the Proxy URL in the Spectranet window uses ws:// (not wss://) for local development, and that the port matches the PORT environment variable.

Clone this wiki locally