NuxtN
Nuxt12mo ago
Alireza

Difference between server plugin and server route middleware

Hi @kapa.ai
I want to run a function that get's the location of the user form the request (provided by cloudflare). I am using const event = useRequestEvent() which would return value on server requests and undefined on browser navigation.

It works in /middleware/location.global.ts
I can get the context.cf out of useRequestEvent() and update pinia store value and use that on subsequent client side navigations. It get's updated after reload or other server requests.

It also works when you put the function to run in /plugins/location.server.ts. My understanding is that the server plugins will run on server requests? Is there a difference between deploying Nuxt on a long running node vs Cloudflare Worker in that sense?

What is the difference between the 2 approaches?
Was this page helpful?