TLDR
I would like to implement some way for middleware to be ran in the context of server/client/isomorphic on a per middleware basis.
Problem
Example Playground with Router, Layout and Page middleware
At the moment we are able to control how middleware are applied on a global basis using the mode of either ssr or universal.
| Mode |
Application of middleware |
| ssr |
Runs middleware on client page boot and each page transition |
| universal |
Runs middleware on server render and each page transition |
What this means it that if i have something like a middleware that should only run on the client pages but I am running in universal mode I don't have the option to use the middleware system completely for my concern.
Proposed API
Current middleware would continue to work as is in the way above.
I propose adding annotations to middleware similar to how we handle plugins.
/middleware
/middleware.client.js
/middleware.server.js
This would allow me as a developer who has specific needs to tell nuxt which contexts i would like to run my middleware in without affecting the current implementation in any way.
I would expect these annotations to work in this way.
| Middleware File Name |
Application of middleware |
*.client.js |
Runs middleware on client page boot and each page transition |
*.server.js |
Runs middleware on server render only |
*.js |
Fallback runs in the way that it always had with using the mode to determine application |
I am totally open to implement this feature if it is desirable.
Updates
- Removed isomorphic.js option that would run on both client and server
TLDR
I would like to implement some way for middleware to be ran in the context of server/client/isomorphic on a per middleware basis.
Problem
Example Playground with Router, Layout and Page middleware
At the moment we are able to control how middleware are applied on a global basis using the
modeof either ssr or universal.What this means it that if i have something like a
middlewarethat should only run on the client pages but I am running inuniversalmode I don't have the option to use the middleware system completely for my concern.Proposed API
Current middleware would continue to work as is in the way above.
I propose adding annotations to middleware similar to how we handle plugins.
This would allow me as a developer who has specific needs to tell nuxt which contexts i would like to run my middleware in without affecting the current implementation in any way.
I would expect these annotations to work in this way.
*.client.js*.server.js*.jsI am totally open to implement this feature if it is desirable.
Updates