In my nuxt 3 App, for data fetching I wanna set a baseURL for all my API calls. As I get this baseURL from enviroment variable. How to set the the baseURL?
I warp the useFetch with composables, but then I can't get the baseURL as useRuntimeConfig() is not accessable there.
// My composables function
const baseURL = "how to get baseURL from process.env";
export const myFetch = async (url: string) => {
const options = {
baseURL: baseURL,
};
return await useFetch(url, options);
}
You can access the runtime config by doing so
export default () => {
const config = useRuntimeConfig()
console.log(config)
}
As shown here: https://github.com/nuxt/framework/discussions/3215#discussioncomment-3088206
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With