Middleware is not applied to static paths (like before)
See original GitHub issueVerify canary release
- I verified that the issue exists in Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.4.0: Mon Feb 21 20:34:37 PST 2022; root:xnu-8020.101.4~2/RELEASE_X86_64
Binaries:
Node: 16.13.0
npm: 8.1.0
Yarn: 3.2.0
pnpm: N/A
Relevant packages:
next: 12.1.5-canary.0
react: 17.0.2
react-dom: 17.0.2
What browser are you using? (if relevant)
Chrome 99
How are you deploying your application? (if relevant)
aws, next start
Describe the Bug
Opening the issue again because for some reason the previous one was deleted (???)
We are using middleware in order to protect static assets from unauthenticated users.
Until v12.1.3 it was possible to protect them using middleware.
Currently, middleware is not invoked when fetching an asset, e.g. /_next/static/chunks/something.js
or /_next/static/media/image.png
Looks like its a result of #32601
Expected Behavior
I do understand that this feature was not “officially” supported, but middleware should be invoked also for static assets.
An idea might be separating page/api middleware and static assets middleware (e.g under _next folder) or a custom configuration that supports it.
To Reproduce
• Add a middleware - pages/_middleware.js • Observe that requests under _next path are not invoked
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top GitHub Comments
With the most recent canary we have enabled back the ability to run middleware in front of static assets which means that this behaviour is back. Glad to see there are important use cases for it 🎉
Thanks!
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.