Skip to content

vinext: middleware.ts does not run for files in public/ #743

Closed

Description

@magurotuna

In a vinext app deployed with Void, requests for files in public/ skip middleware.ts. Cloudflare serves these files from Workers Static Assets before the Worker runs. Next.js runs middleware for every path its matcher covers, including public/ files. Therefore, on Void, a middleware auth check on /report.pdf does not protect the file.

vinext fixed this in its own Cloudflare setup (cloudflare/vinext#3217). vinext init writes run_worker_first: ["/*", "!/_next/static/*", ...] (cloudflare/vinext#3804). Void can't use the same setting: since #660, static files skip the Worker, in order to not count toward the Workers Free limit of 100,000 requests a day.

Possible approach: if the app has middleware.ts, run the Worker first only for the paths its matcher covers. Apps without middleware keep the current routing.

Worker-first routing alone is not enough though. The build wrapper sends every GET or HEAD 404 from the framework to env.ASSETS (createAssetFallback), so a file is still served when middleware returns 404 for it.

Found while working on #742.

Activity

  1. self-assigned this
    on Nov 8, 2026
  2. added a commit that references this issue on Nov 8, 2026
    d2b4fd6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions