Alireza
Alireza
NNuxt
Created by Alireza on 1/18/2025 in #❓・help
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?
20 replies
NNuxt
Created by Alireza on 12/16/2024 in #❓・help
SSR friendly usePreviousRoute()?
Say a visitor goes to a blog category page at /cat/tutorials and then clicks on a blog post going to /article/hello. The can also reach to /article/hello from other categories like /cat/videos. Now I want to create breadcrumbs that would show Posts > Tutorials > Hello or Posts > Videos > Hello providing the use navigation path. There will also be a default one if a user directly accesses the article page. How would you go about that? I was thinking maybe it is possible to access the from of the routeMiddleware?
<!-- the <Article> component -->
<script setup lang="ts">
definePageMeta({
middleware: [
function (to, from) {
// somehow make the from available to the component
},
'auth',
],
});

// then access the `from` here and build the breadcrumbs
</script>
<!-- the <Article> component -->
<script setup lang="ts">
definePageMeta({
middleware: [
function (to, from) {
// somehow make the from available to the component
},
'auth',
],
});

// then access the `from` here and build the breadcrumbs
</script>
24 replies
NNuxt
Created by Alireza on 9/7/2024 in #❓・help
Example of updating app.config at runtime
Doc says app.config is reactive and can be changed at runtime. The docs does not provide any examples though. https://nuxt.com/docs/guide/directory-structure/app-config I am looking for an example of how to do that and what are the use cases of this feature. For example, if we have a color: "#fff" in the app.config, can it be changed at the runtime after fetching the value from the database after the user login? like color.value = userColor It would be also nice if anyone could point to a GitHub repo that uses this or even how to search GitHub to find such a use case.
2 replies
NNuxt
Created by Alireza on 3/18/2024 in #❓・help
how to define types for runtimeConfig keys?
example:
runtimeConfig: {
public: {
//-> this can be of type 'apple' | 'banana' | 'cherry'
fruit: 'apple',
}
}
runtimeConfig: {
public: {
//-> this can be of type 'apple' | 'banana' | 'cherry'
fruit: 'apple',
}
}
2 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?
For example I have a collection of routes under /server/api/user and I need all of them to run /server/middleware/auth.ts . How do you go about it?
5 replies
NNuxt
Created by Alireza on 2/16/2023 in #❓・help
Recommended place to put custom types
I am putting my custom type defs in the /utils directory. Is there a better place to put them? What do you do usually?
6 replies