Alireza
Alireza
NNuxt
Created by Alireza on 1/18/2025 in #❓・help
Difference between server plugin and server route middleware
@kapa.ai Could you elaborate on this part?
The key difference between this and middleware is that server plugins run before the Vue app is created, while middleware runs as part of the Vue routing process. This makes server plugins suitable for early request processing and setting up server-specific state or services.
How you can run composables in the Nuxt plugins before the Vue app is created?
20 replies
NNuxt
Created by Alireza on 1/18/2025 in #❓・help
Difference between server plugin and server route middleware
@kapa.ai Can you elaborate on this?
Using a Nuxt server plugin (/plugins/location.server.ts) would run the location-fetching code when the Nuxt app initializes on the server.
The initialization of the Nuxt app on the server, does it happen on each request to server? or only once when the server starts using nuxi preview
20 replies
NNuxt
Created by Alireza on 1/18/2025 in #❓・help
Difference between server plugin and server route middleware
@kapa.ai I think there is a misunderstanding. I did not mean Nitro server plugin. I meant a regular nuxt plugin with .server suffix.. You can suffix a plugin with .server to tell Nuxt to rin the plugin on server only.
20 replies
NNuxt
Created by Alireza on 12/16/2024 in #❓・help
SSR friendly usePreviousRoute()?
I appreciate if anyone could share if they have experience with this.
24 replies
NNuxt
Created by Alireza on 12/16/2024 in #❓・help
SSR friendly usePreviousRoute()?
@kapa.ai Yeah, looks like useState is a better approach. The problem with the router is when: 1. user navigates from category to article 2. we have the previous route 3. the for some reason user reloads the page, and we lose the previous. So we better use something that keeps it as a state that is presisted somehow?
24 replies
NNuxt
Created by Alireza on 12/16/2024 in #❓・help
SSR friendly usePreviousRoute()?
@kapa.ai Would that work on SSR?
24 replies
NNuxt
Created by Alireza on 12/16/2024 in #❓・help
SSR friendly usePreviousRoute()?
@kapa.ai how about a Nuxt plugin and making the previousRoute globally available in the router?
24 replies
NNuxt
Created by Pawieplays on 3/12/2024 in #❓・help
fetch failed
Look like you are using nuxt-auth module
6 replies
NNuxt
Created by Pawieplays on 3/12/2024 in #❓・help
fetch failed
Can you provide more context?
6 replies
NNuxt
Created by Alireza on 7/2/2023 in #❓・help
Is it possible to select/define which server middlewares should be run on a specific server route?
Thanks @Cake
5 replies
NNuxt
Created by Alireza on 7/2/2023 in #❓・help
Is it possible to select/define which server middlewares should be run on a specific server route?
Would something like this work?
export default defineEventHandler( async (event) => {

const url = getRequestURL(event);

if (url.pathname.startsWith("/api/user") ){

const user = getUser()
if (!user) {
throw createError({
statusCode: 401,
statusMessage: "unauthorized",
});
}
}
})
export default defineEventHandler( async (event) => {

const url = getRequestURL(event);

if (url.pathname.startsWith("/api/user") ){

const user = getUser()
if (!user) {
throw createError({
statusCode: 401,
statusMessage: "unauthorized",
});
}
}
})
5 replies
NNuxt
Created by AngeloK on 6/1/2023 in #❓・help
Optimistic UI with useAsyncData?
onRequest etc are called interceptors. The come from the ofetch package which is same as the $fetch It should be possible to do it like this in theory
const { data, pending, error, refresh } = await useAsyncData(
'mountains',
() => $fetch('https://api.nuxtjs.dev/mountains', {
async onRequest({ request, options }) {...}
})
)
const { data, pending, error, refresh } = await useAsyncData(
'mountains',
() => $fetch('https://api.nuxtjs.dev/mountains', {
async onRequest({ request, options }) {...}
})
)
2 replies
NNuxt
Created by Alireza on 2/16/2023 in #❓・help
Recommended place to put custom types
Just to make sure, there is no auto-import for types yet? right?
6 replies