diff --git a/docs/content/migration/8.runtime-config.md b/docs/content/migration/8.runtime-config.md index 33ddf98b9..2591f50e7 100644 --- a/docs/content/migration/8.runtime-config.md +++ b/docs/content/migration/8.runtime-config.md @@ -25,9 +25,11 @@ import { defineNuxtConfig } from 'nuxt' export default defineNuxtConfig({ runtimeConfig: { - secretKey: '', // variable that can only be accessed on the server side + // Private config that is only available on the server + apiSecret: '123', + // Config within public will be also exposed to the client public: { - BASE_URL: process.env.BASE_URL || 'https://nuxtjs.org' // variable that can also be accessed on the client side + apiBase: '/api' } }, }) @@ -35,20 +37,27 @@ export default defineNuxtConfig({ ```vue [pages/index.vue] ``` ```ts [server/api/hello.ts] -const config = useRuntimeConfig().public +const config = useRuntimeConfig() export default (req, res) => { - // you can now access config.BASE_URL - return { - baseURL: config.BASE_URL - } + // In server, you can now access config.apiSecret, in addition to config.public + console.log(config.apiSecret) + console.log(config.public.apiBase) } ``` +```ini [.env] +# Runtime config values are automatically replaced by matching environment variables at runtime +NUXT_API_SECRET=api_secret_token +NUXT_PUBLIC_API_BASE=https://nuxtjs.org +``` + ::