fix(plugin-vite): forward non-Fresh 404s to next middleware (server.proxy, etc.)#3882
Open
sanjibani wants to merge 1 commit into
Open
fix(plugin-vite): forward non-Fresh 404s to next middleware (server.proxy, etc.)#3882sanjibani wants to merge 1 commit into
sanjibani wants to merge 1 commit into
Conversation
…ver.proxy)
Fresh's dev-server middleware previously short-circuited every request
that reached it: when Fresh's router returned 404 (no matching route),
the middleware wrote the 404 response and never called next(). That
swallowed Vite's `server.proxy` middleware (and any user-installed
middleware that runs after Fresh), so a config like:
server: { proxy: { '/api': 'http://127.0.0.1:8000' } }
returned 404 for /api/* requests instead of forwarding them.
Fix: when Fresh's handler returns 404, call next() so the request can
be handled by vite's proxy middleware or any downstream handler. Match
the existing pattern for static files and Vite internal URLs.
Adds a regression test with a separate vite.config.ts fixture
(server_proxy) that proxies /api to a deno.serve target. Test verifies
the target receives the forwarded request after my fix lands.
Closes freshframework#3814.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fresh's dev-server middleware short-circuited every request that reached it: when Fresh's router returned 404, the middleware wrote the 404 response and never called next(). That swallowed Vite's
server.proxymiddleware and any downstream handler.Fix: when Fresh's handler returns 404, call next() so the request can flow to vite's proxy middleware. Matches the existing pattern for static files and Vite internal URLs (IGNORE_URLS, /node_modules, moduleGraph checks).
Repro from the issue: a vite config like
returned 404 for /api/* requests instead of forwarding them.
Adds a regression test with a separate vite.config.ts fixture (server_proxy) that proxies /api to a deno.serve target. Test verifies the target receives the forwarded request.
Closes #3814.