Global Middleware on first load both side
See original GitHub issueEnvironment
- Operating System:
Linux
- Node Version:
v16.14.2
- Nuxt Version:
3.0.0-27484505.9f6eff7
- Package Manager:
yarn@1.22.18
- Builder:
vite
- User Config:
vite
,privateRuntimeConfig
,publicRuntimeConfig
,css
,buildModules
,intlify
,vueuse
- Runtime Modules:
-
- Build Modules:
@intlify/nuxt3@0.1.10
,@pinia/nuxt@0.1.8
,@vueuse/nuxt@8.2.5
Reproduction
https://stackblitz.com/edit/github-dypzgk
Describe the bug
On first load, the global middleware get executed on both side (server and client). In Nuxt 2, if the app is in universal mode, at first load the middleware get executed only by server side.
Additional context
No response
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Is it possible for middleware to be executed only on client side
global middleware still doesn't run clientside on initial page load. Not sure if that's just by design. My core problem may be from...
Read more >Node Express 4 middleware after routes - Stack Overflow
The correct answer is using the res.on("finish", cb) callback. i.e.: express.use(function(req, res, next) { console.log("before"); ...
Read more >Writing middleware for use in Express apps
Every time the app receives a request, it prints the message “LOGGED” to the terminal. The order of middleware loading is important: middleware...
Read more >Advanced Features: Middleware - Next.js
Middleware allows you to run code before a request is completed, then based on the incoming request, you can modify the response by...
Read more >Middleware directory - Nuxt
A middleware receives the context as the first argument. ... With ssr: false , middlewares will be called on the client-side in both...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@pskclub You can use
if (process.server)
for example if you want to run it only on server.I have also ran into this issue. I find a way to judge whether it is running in server side or in client.
process.client
orprocess.server
. if code is running in client side,process.client
will be true. So if you want to count page enter times, you can addif (process.client)
block.useNuxtApp()
. If you need to access nuxtApp by coincidence, you can useuseNuxtApp().ssrContext
to judge, because this property only exist in server side.