N
Nuxt3y ago
cosbgn

Why I need to add server env variables to runtimeConfig?

Could someone explain me why I need to add API_ROUTE_SECRET inside runtimeConfig?
export default defineNuxtConfig({
runtimeConfig: { // The private keys which are only available within server-side
API_ROUTE_SECRET: process.env.API_ROUTE_SECRET,

// Keys within public, will be also exposed to the client-side
public: {
apiBase: '/api'
}
}
})
export default defineNuxtConfig({
runtimeConfig: { // The private keys which are only available within server-side
API_ROUTE_SECRET: process.env.API_ROUTE_SECRET,

// Keys within public, will be also exposed to the client-side
public: {
apiBase: '/api'
}
}
})
Since is only server-side I can simply access it like process.env.API_ROUTE_SECRET Why would I add it also here?
3 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
peac
peac2y ago
for some reason it was not working until i prefixed the env variables with NUXT_PUBLIC_ https://nuxt.com/docs/guide/going-further/runtime-config#environment-variables
Nuxt
Runtime Config · Nuxt Advanced
Nuxt provides a runtime config API to expose configuration within your application.
cosbgn
cosbgnOP2y ago
Yeah, I've been wondering the same forever. I never add them and simply use them in my server routes as process.env.x never had an issue Doesn't make sense IMO to add them

Did you find this page helpful?