Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Middleware is not applied to static paths (like before) #35906

Closed
1 task done
danr-za opened this issue Apr 5, 2022 · 5 comments
Closed
1 task done

Middleware is not applied to static paths (like before) #35906

danr-za opened this issue Apr 5, 2022 · 5 comments
Labels
bug Issue was opened via the bug report template.

Comments

@danr-za
Copy link

danr-za commented Apr 5, 2022

Verify 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

@danr-za danr-za added the bug Issue was opened via the bug report template. label Apr 5, 2022
@iamkhalidbashir
Copy link

Yupe this is needed. Critical for us

@mmmulani
Copy link

fwiw I couldn't find a version where the behaviour was as you describe it (except as a bug #31324), and the docs at https://nextjs.org/docs/middleware say:

Middleware runs directly after redirects and headers, before the first filesystem lookup. This excludes /_next files.

on the other hand though, this functionality would be useful imo

@danr-za
Copy link
Author

danr-za commented Apr 13, 2022

as per docs, you're right.
once you install v12.1.2 you'll see that behavior.

@javivelasco
Copy link
Member

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!

@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

5 participants
@mmmulani @javivelasco @iamkhalidbashir @danr-za and others