Nuxt & Universal SSR (50 Qs)•Part 2: Core Architecture & Data Fetching (Mid-Level)
What is Runtime Config vs App Config in Nuxt 3?
senior LevelCode ExampleSystem DesignVue & NuxtHTTP & REST APIs
In Simple Words:
runtimeConfig: Used for environment variables, secrets, and deployment-specific settings. Can be updated at runtime using OS environment variables without rebuilding the application (e.g.NUXT_API_SECRET).- Top-level keys: Private secrets accessible only in server routes.
publickeys: Exposed to both client and server code viauseRuntimeConfig().public.
appConfig: Used for build-time public UI themes, branding, and color schemes viaapp.config.ts.
typescript
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
apiSecret: 'secret_on_server_only', // Private
public: {
apiBaseUrl: 'https://api.example.com' // Public to browser
}
}
});