Commit Graph

21 Commits

Author SHA1 Message Date
a56dfdc422 Merge pull request 'Fix proxy and split server into modules' (#1) from probablycorey/fix-proxy-404s into main
Reviewed-on: #1
2026-03-11 16:34:59 +00:00
542b8f06ca Remove unused dependencies from lock file
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-11 09:31:21 -07:00
869fd18d42 Use redirect: manual to let browser handle redirects
Bun's fetch was following Go's 303 redirects internally, which
caused ECONNRESET errors during the auto-login redirect chain.
Let the browser handle redirects instead.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:36:13 -07:00
383f6a8143 Switch from unix socket to TCP proxy
Proxy to Go server on 127.0.0.1:8000 instead of unix socket.
Go sees localhost connections as trusted for auto-login.
Removes all the unix socket, IP forwarding, and socket path
plumbing complexity.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:32:42 -07:00
24b9629f0f Forward client IP to Go server for auto-login trust
The Go server checks if the client is on a private network for
auto-login. Since we proxy over a unix socket, the Go server
can't see the real client IP. Forward it via X-Forwarded-For
and X-Real-IP headers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:29:01 -07:00
019fca14f1 Update CLAUDE.md to reflect PRODUCTION=true default
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:24:10 -07:00
3bd144c88e Default PRODUCTION to true for system apps
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:23:40 -07:00
08e80a2f92 Strip content-encoding/length from Go responses
Go server always sends gzip regardless of accept-encoding. Bun
decompresses it automatically but leaves the content-encoding
header. Strip it so the toes proxy doesn't try to decompress
the already-decompressed response.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:11:37 -07:00
74155d3d0a Strip accept-encoding to prevent gzip in proxy chain
Toes' Bun fetch auto-decompresses responses. If Go sends gzip
through our proxy, toes gets raw gzip bytes it can't handle.
Stripping accept-encoding tells Go to send uncompressed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 19:04:04 -07:00
e197a6d3bb Use decompress: false for transparent proxy passthrough
Bun's fetch has a decompress option that passes responses through
without interpreting content-encoding. This replaces all the manual
header stripping workarounds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:57:19 -07:00
a344e293f1 Buffer request body before proxying to unix socket
Streaming req.body through the double proxy (toes -> bun -> go)
caused POST requests to fail. Buffer the body as an ArrayBuffer
first so content-length is set correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 18:02:12 -07:00
02482d9beb Split server.ts into proxy, binary, and server modules
- proxy.ts: HTTP and WebSocket proxy to Go unix socket
- binary.ts: Go binary download, validation, spawning, lifecycle
- server.ts: entry point wiring everything together

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:57:11 -07:00
82febdbf7f Strip content-encoding from proxied responses
Bun decompresses gzip responses internally but leaves the
Content-Encoding: gzip header, causing browsers to fail trying
to decompress already-decompressed content.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:45:27 -07:00
3fe4116ec7 Strip accept-encoding to avoid ZlibError in proxy chain
The Go server returns gzip responses, but when Bun proxies these
through to the toes proxy, the double-proxy causes a ZlibError
during decompression. Stripping accept-encoding tells the Go
server to send uncompressed responses.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:36:24 -07:00
be6719733b Listen on :: (dual-stack) instead of 0.0.0.0
Toes proxy fetches via localhost which may resolve to ::1 on Linux.
Listening on :: accepts both IPv4 and IPv6 connections.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:35:11 -07:00
4e2e0c9c5f Listen on 0.0.0.0 to ensure IPv4 connectivity
tronbyt.toes.local resolves to an IPv4 address while toes.local
uses IPv6, so the toes proxy couldn't reach the Bun server.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:34:07 -07:00
6774b456a9 Don't forward body for GET/HEAD requests in proxy
Passing req.body (a ReadableStream) for GET requests could cause
the unix socket fetch to hang waiting for body data, especially
when the upstream toes proxy has already stripped content-length.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:31:19 -07:00
89bf052ca1 Return 200 from /ok while Go server is still starting
Toes health-checks /ok during startup. The Go server can take a
while to become healthy (cloning system apps repo on first run),
so return 200 while the process is alive but not yet ready.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:19:27 -07:00
84ce472c87 Auto-download Go binary on startup and validate setup
The postinstall script doesn't run on toes (package.json is
transformed during deploy), so the binary was never downloaded.
Now the server downloads it from GitHub releases if missing.
Added validate() to catch missing DATA_DIR and non-executable
binary with clear error messages.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-10 17:16:05 -07:00
387f746f8c ok 2026-03-10 16:53:05 -07:00
ca13947bfb init 2026-03-10 16:07:23 -07:00