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
{{ message }}
Repository navigation
Let global middleware declare the paths it runs on #808
Void's own dashboard does the same in platform/packages/dashboard/middleware/01.auth.ts, with PUBLIC_PATHS and PUBLIC_PREFIXES.
That's only boilerplate, but having middleware at all also costs every static file its free request. resolveAssetWorkerBypass() in packages/void/src/asset-worker-bypass.ts gives up the bypass as soon as there's any middleware:
facts.hasMiddleware||
So in a build with middleware, every hashed JS, CSS and image file starts the Worker, and each middleware runs for it. Any middleware that reads a session, KV or D1 has to skip asset paths by hand, or every asset waits on that read. Void can't tell which middleware might touch /assets/, so it has to assume all of them do.
Proposal
Let a middleware file export the paths it runs on, in the same glob syntax as run_worker_first:
// middleware/04.admin.tsexportconstmatcher=['/admin','/admin/**'];exportdefaultdefineMiddleware(async(c,next)=>{// runs only for /admin and below});
A file without matcher runs on every request, as today, so existing apps see no change.
! patterns exclude paths, as in run_worker_first, so a middleware that sets shared data for every page can still leave assets out with ['/**', '!/assets/**'].
Files still run in filename order; one that doesn't match is skipped.
hasMiddleware becomes "has middleware that can reach the assets folder": if every file has a matcher and none of them can reach it, checked with patternCanReachUnder() as the bypass already does for route, page and auth patterns, the bypass stays on.
Matching on the request path alone keeps it decidable at build time. A function form, like matcher: (c) => …, couldn't be checked against the assets folder, so it would have to keep the Worker in front.
Prior art
Next.js: export const config = { matcher: [...] } in middleware.ts, with path patterns and negative lookaheads, so _next/static can be left out.
TanStack Start: middleware attached to a route runs only for that route and below.
TanStack Router: beforeLoad on a layout route runs for its children only.
Activity
yangshun commentedon Nov 13, 2026
I'd like this feature as well, but two points I hope we can try to achieve in the eventual API: