Skip to content

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

Open

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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