1👍
✅
With Nuxt 3 syntax you can write the same as following:
const isProdEnv = process.env.NODE_ENV === 'production'
const testEndpoint = 'https://TESTENDPOINT'
const prodServicesEndpoint = 'https://PRODENDPOINT'
const servicesEndpoint = isProdEnv ? prodServicesEndpoint : testServicesEndpoint
export default defineNuxtConfig({
runtimeConfig: {
public: {
apiBaseUrl: servicesEndpoint
}
},
// ...
})
Then you can access it in your code with:
const { public: { apiBaseUrl }} = useRuntimeConfig()
See the documentation for additional info.
Source:stackexchange.com