-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[Feature Request] option to skip request in dev middleware #12747
Copy link
Copy link
Closed
Labels
vite-pluginRelating to the `@cloudflare/vite-plugin` packageRelating to the `@cloudflare/vite-plugin` package
Description
Describe the solution
Frameworks with hybrid rendering (mix of prerendered and SSR routes) need a way to have the Cloudflare Vite plugin not intercept all requests during dev.
In Astro to support prerender environments other than workerd withastro/astro#15684, we need a way for the dev server to match the build behavior.
Proposal
Add an optional callback to PluginConfig that controls whether a request should be dispatched to miniflare or fall through to Vite:
shouldHandle?: (request: Request) => boolean | Promise<boolean>;When shouldHandle returns false, the request skips both the preMiddleware worker dispatch and the catch-all post-middleware, falling through to Vite as if the plugin wasn't there.
One way to implement this would be marking skipped requests with a new kRequestType value so the post-middleware knows to call next():
if (shouldHandle && !(await shouldHandle(request))) {
req[kRequestType] = "skip";
return next();
}Usage
cloudflare({
shouldHandle: (request) => {
return !prerenderRoutes.has(new URL(request.url).pathname);
},
});Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
vite-pluginRelating to the `@cloudflare/vite-plugin` packageRelating to the `@cloudflare/vite-plugin` package
Type
Projects
Status
Done