Skip to content

Fix -ui-dev serving 502 for every page - #6

Merged
comstud merged 1 commit into
mainfrom
comstud/fix-ui-dev-proxy
Aug 30, 2026
Merged

Fix -ui-dev serving 502 for every page#6
comstud merged 1 commit into
mainfrom
comstud/fix-ui-dev-proxy

Conversation

@comstud

@comstud comstud commented Aug 30, 2026

Copy link
Copy Markdown
Collaborator

The dev-mode reverse proxy was built with NewSingleHostReverseProxy, which sets Director, and then had Rewrite assigned on top of it. ReverseProxy accepts exactly one of the two: with both set, ServeHTTP hands the request straight to the error handler and returns

http: proxy error: ReverseProxy must have exactly one of Director or
Rewrite set

so every non-/api request under -ui-dev answered 502 instead of reaching the vite dev server. Running the UI against a live backend that way has never worked.

Building the proxy from Rewrite alone keeps the intended behaviour -- Rewrite is the newer API and is what the SetURL/Host lines were written against -- and drops the Director that was only ever an artifact of the constructor.

Nothing outside dev mode is affected: the branch is reached only when -ui-dev is passed, which is why the whole test suite and CI stayed green either way. libs/services had no tests at all, so the regression test comes with its own file.

The test stands in for vite by binding localhost:4199, the hardcoded target, and skips rather than fails when that port is already taken. It drives a real server rather than a ResponseRecorder because ReverseProxy takes a different path when the request context has no Done channel -- which is part of why this survived so long unnoticed.

Claude-Session: https://claude.ai/code/session_01AXB8suZYfpYZsSaoEps67m

The dev-mode reverse proxy was built with NewSingleHostReverseProxy, which
sets Director, and then had Rewrite assigned on top of it. ReverseProxy
accepts exactly one of the two: with both set, ServeHTTP hands the request
straight to the error handler and returns

  http: proxy error: ReverseProxy must have exactly one of Director or
  Rewrite set

so every non-/api request under -ui-dev answered 502 instead of reaching
the vite dev server. Running the UI against a live backend that way has
never worked.

Building the proxy from Rewrite alone keeps the intended behaviour --
Rewrite is the newer API and is what the SetURL/Host lines were written
against -- and drops the Director that was only ever an artifact of the
constructor.

Nothing outside dev mode is affected: the branch is reached only when
-ui-dev is passed, which is why the whole test suite and CI stayed green
either way. libs/services had no tests at all, so the regression test
comes with its own file.

The test stands in for vite by binding localhost:4199, the hardcoded
target, and skips rather than fails when that port is already taken. It
drives a real server rather than a ResponseRecorder because ReverseProxy
takes a different path when the request context has no Done channel --
which is part of why this survived so long unnoticed.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AXB8suZYfpYZsSaoEps67m
@comstud
comstud merged commit 48eee46 into main Aug 30, 2026
5 checks passed
@comstud
comstud deleted the comstud/fix-ui-dev-proxy branch August 30, 2026 05:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant