You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Filing as an inquiry rather than a pure bug report β want to confirm whether this is known/intentional before sending a PR.
In our setup, env["REQUEST_URI"] sometimes arrives at ViteRuby::DevServerProxy as an RFC 7230 Β§5.3.2 absolute-form URI (https://host/vite-dev/...) rather than origin-form (/vite-dev/...). This causes DevServerProxy to forward an absolute-form request-target to the Vite dev server. Vite's baseMiddleware then returns the "public base URL of /vite-dev/ β did you mean to visit β¦" error page because req.url.startsWith('/vite-dev/') is false when req.url is a full URL.
normalize_uri already exists to defend against this class of problem (the comment reads "Hanami adds the host and port"), but the regex is narrow to host:port/:
HOST_WITH_PORT_REGEX=%r{^(.+?)(:\d+)/}defrewrite_uri_for_vite(env)uri=env.fetch("REQUEST_URI"){ ... }env["PATH_INFO"],env["QUERY_STRING"]=(env["REQUEST_URI"]=normalize_uri(uri)).split("?")enddefnormalize_uri(uri)uri.sub(HOST_WITH_PORT_REGEX,"/")# Hanami adds the host and port..sub(".ts.js",".ts").sub(/\.(sass|scss|styl|stylus|less|pcss|postcss)\.css$/,'.\1')end
With REQUEST_URI = "https://our.frontend.dev/vite-dev/@vite/client":
HOST_WITH_PORT_REGEX requires an explicit :\d+. Default HTTPS (443) has no port in the URI, so the regex does not match.
normalize_uri returns the string unchanged.
PATH_INFO is rewritten to the full URL.
rack-proxy uses source_request.fullpath verbatim, sending GET https://our.frontend.dev/vite-dev/@vite/client HTTP/1.1 to the Vite dev server.
Was HOST_WITH_PORT_REGEX restricted to host:port/ intentionally, or simply because Hanami was the only shape encountered at the time? Absolute-form in REQUEST_URI seems plausibly common under TLS-terminating reverse proxies and Rack instrumentation libraries.
Would a broadening like this be acceptable? Happy to send a PR with tests:
No minimal repro yet β in our own app the absolute REQUEST_URI originates somewhere in a complex Rack/Puma load path we haven't fully isolated. The general-principle question is whether DevServerProxy should be resilient to the RFC absolute-form shape given it already has a defense for the Hanami variant.
If a reproduction is required before you want to look at this, I can work on isolating a minimal Rack middleware that reproduces the env shape.
Vite's own debug (DEBUG=vite-plugin-ruby:*) confirms base: '/vite-dev/' resolves correctly and the plugin chain is intact β the issue is purely that the request-target arriving at Vite is absolute-form.
Screenshots π·
(None β error text above is the complete browser output.)
bundle update vite_ruby.Description π
Filing as an inquiry rather than a pure bug report β want to confirm whether this is known/intentional before sending a PR.
In our setup,
env["REQUEST_URI"]sometimes arrives atViteRuby::DevServerProxyas an RFC 7230 Β§5.3.2 absolute-form URI (https://host/vite-dev/...) rather than origin-form (/vite-dev/...). This causesDevServerProxyto forward an absolute-form request-target to the Vite dev server. Vite'sbaseMiddlewarethen returns the "public base URL of /vite-dev/ β did you mean to visit β¦" error page becausereq.url.startsWith('/vite-dev/')is false whenreq.urlis a full URL.normalize_urialready exists to defend against this class of problem (the comment reads "Hanami adds the host and port"), but the regex is narrow tohost:port/:https://github.com/ElMassimo/vite_ruby/blob/vite_ruby%403.10.2/vite_ruby/lib/vite_ruby/dev_server_proxy.rb
With
REQUEST_URI = "https://our.frontend.dev/vite-dev/@vite/client":HOST_WITH_PORT_REGEXrequires an explicit:\d+. Default HTTPS (443) has no port in the URI, so the regex does not match.normalize_urireturns the string unchanged.PATH_INFOis rewritten to the full URL.rack-proxyusessource_request.fullpathverbatim, sendingGET https://our.frontend.dev/vite-dev/@vite/client HTTP/1.1to the Vite dev server.baseMiddlewarerejects.Questions:
Is this a known limitation? I searched open/closed issues and didn't find a match (closest are Dev server is proxying requests starting with @ that should be handled by RailsΒ #194 and vite-plugin-ruby 3.1.1 breaks HMR proxy setupΒ #231, which are different).
Was
HOST_WITH_PORT_REGEXrestricted tohost:port/intentionally, or simply because Hanami was the only shape encountered at the time? Absolute-form inREQUEST_URIseems plausibly common under TLS-terminating reverse proxies and Rack instrumentation libraries.Would a broadening like this be acceptable? Happy to send a PR with tests:
Reproduction π
No minimal repro yet β in our own app the absolute
REQUEST_URIoriginates somewhere in a complex Rack/Puma load path we haven't fully isolated. The general-principle question is whetherDevServerProxyshould be resilient to the RFC absolute-form shape given it already has a defense for the Hanami variant.If a reproduction is required before you want to look at this, I can work on isolating a minimal Rack middleware that reproduces the env shape.
Vite Ruby Info
Run
bin/rake vite:infoand provide the output:Additional versions from Gemfile.lock / yarn.lock:
rack-proxyrackpumavite(Node)vite-plugin-ruby(Node)Logs π
Symptom in the browser:
Debug confirming
REQUEST_URIis absolute beforeDevServerProxyruns (prepended logger in front offorward_to_vite_dev_server):For comparison, a sibling app on the same infra produces origin-form and works:
Vite's own debug (
DEBUG=vite-plugin-ruby:*) confirmsbase: '/vite-dev/'resolves correctly and the plugin chain is intact β the issue is purely that the request-target arriving at Vite is absolute-form.Screenshots π·
(None β error text above is the complete browser output.)