Skip to content

Dev server proxy returns 502 on rack-proxy 1.0 (Host-derived backend refused) #622

Closed

Description

@KaptajnKold
  • I have tried upgrading by running bundle update vite_ruby.
  • I have read the [troubleshooting section] before opening an issue.

Description 📖

Since vite_ruby 3.10.3 relaxed the rack-proxy constraint (#617, closes #619), Bundler can resolve rack-proxy 1.0.x. ViteRuby::DevServerProxy is not compatible with it: every asset request through the dev server proxy returns 502 with no headers.

rack-proxy 1.0 closed an open-proxy hole by refusing a backend derived from the request's Host header unless the middleware is built with allow_dynamic_backend: true (CHANGELOG):

backend = env.delete("rack.backend") || @backend
if backend.nil?
  unless @allow_dynamic_backend
    return [502, {}, []]
  end

Choosing the backend by rewriting Host is precisely how DevServerProxy works — forward_to_vite_dev_server sets env["HTTP_HOST"] = config.host and never sets :backend. Passing a :logger shows the refusal:

rack-proxy: refusing Host-derived backend "localhost"
(no :backend configured; pass allow_dynamic_backend: true to opt in)

ViteRails::Engine builds the middleware with ssl_verify_none: true only, so an app cannot opt in without replacing the middleware.

Because the refusal is [502, {}, []], the response carries no Content-Type at all. Browsers report an empty MIME type rather than anything actionable — in Firefox, NS_ERROR_CORRUPTED_CONTENT plus "Loading module ... was blocked because of a disallowed MIME type ("")".

Who is affected: development, and only when assets go through the proxy. vite_rails 3.11.0 began writing skipProxy: true into new installations, so a fresh vite install is unaffected — which is probably why this hasn't surfaced yet. Apps that predate that, or never set the key, get the library default skipProxy: false and break on bundle update. Test suites stay green either way, since the test environment builds assets rather than proxying them.

skipProxy is not a general workaround. It is the obvious escape hatch and it does work — but not for apps that set base. With skipProxy: true, Manifest#prefix_asset_with_host builds URLs from config.origin, which is only "#{protocol}://#{host_with_port}" and drops base. An app with "base": "/m" emits http://localhost:3036/vite-dev/... while the dev server serves /m/vite-dev/..., so every asset 404s and Vite says so itself:

The server is configured with a public base URL of /m/vite-dev/ -
did you mean to visit /m/vite-dev/vite-dev/@vite/client instead?

Reproducible by adding "base": "/m" to the reproduction's config/vite.json. Raising it here only because it closes off the workaround for anyone mounted under a path prefix — happy to file it separately if you would rather track it on its own.

Two possible fixes, both cheap: build the middleware with allow_dynamic_backend: true (optionally alongside a backend_allowed? allowlist pinned to config.host), or set :backend explicitly from config instead of rewriting Host. Happy to open a PR for either if you have a preference.

Reproduction 🐞

https://github.com/KaptajnKold/vite-rack-proxy-repro

bundle install
bin/repro

It boots the Vite dev server and Rails and requests the same asset twice — once straight from Vite as a control, once through Rails:

rack-proxy 1.0.1
vite_ruby  3.10.4

--- direct to the Vite dev server (control) ---
status=200 content-type=text/javascript bytes=205351
--- same asset through Rails (ViteRuby::DevServerProxy) ---
status=502 content-type= bytes=0

Changing rack-proxy to 0.8.3 in the Gemfile makes both lines 200. That is the whole bisect.

Also reproduced against main (1285696) using the Gemfile lines in CONTRIBUTING.md — identical 502.

Vite Ruby Info
bin/vite present?: true
vite_ruby: 3.10.4
vite_rails: 3.11.1
rails: 7.2.3.2
ruby: ruby 3.4.5 (2025-07-16 revision 20cda200d3) +PRISM [arm64-darwin24]
node: v24.12.0
npm: 11.6.2
rack-proxy: 1.0.1   (not listed by vite:info; added by hand)

Logs 📜

The proxy fails before Vite is involved, so DEBUG=vite-plugin-ruby:* bin/vite dev shows a healthy dev server and no matching request — the 502 is generated inside the Rails process. The rack-proxy log line quoted above is the relevant output; it appears once a :logger is passed to the middleware.

Screenshots 📷

Firefox console when loading a page whose entrypoints go through the proxy:

GET http://localhost:8000/vite-dev/entrypoints/application.ts   NS_ERROR_CORRUPTED_CONTENT
GET http://localhost:8000/vite-dev/@vite/client                 NS_ERROR_CORRUPTED_CONTENT

Loading module from "http://localhost:8000/vite-dev/@vite/client" was blocked
because of a disallowed MIME type ("").

Investigated and drafted with an AI assistant. The reproduction was run and verified end to end — including against main, and in both directions across the rack-proxy version bisect.

Activity

  1. added
    bug: pending triage
    on Aug 28, 2026
  2. added a commit that references this issue on Aug 31, 2026
    3486248
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug: pending triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions