Skip to content

fix(plugin-vite): forward non-Fresh 404s to next middleware (server.proxy, etc.)#3882

Open
sanjibani wants to merge 1 commit into
freshframework:mainfrom
sanjibani:fix/plugin-vite-server-proxy
Open

fix(plugin-vite): forward non-Fresh 404s to next middleware (server.proxy, etc.)#3882
sanjibani wants to merge 1 commit into
freshframework:mainfrom
sanjibani:fix/plugin-vite-server-proxy

Conversation

@sanjibani

Copy link
Copy Markdown

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.proxy middleware 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

server: { proxy: { '/api': 'http://127.0.0.1:8000' } }

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.

…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.
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.

Bug: server.proxy not working with @fresh/plugin-vite

1 participant