From d8ee5241412811e33f9c8d665e1a374716847315 Mon Sep 17 00:00:00 2001 From: Manash Sonowal Date: Tue, 12 Apr 2022 13:42:33 +0530 Subject: [PATCH] docs: update runtimeConfig section (#4279) --- .../2.guide/2.features/10.runtime-config.md | 41 +++++++++---------- docs/content/migration/8.runtime-config.md | 14 +++---- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/docs/content/2.guide/2.features/10.runtime-config.md b/docs/content/2.guide/2.features/10.runtime-config.md index aaca924c35..5855d9e2e9 100644 --- a/docs/content/2.guide/2.features/10.runtime-config.md +++ b/docs/content/2.guide/2.features/10.runtime-config.md @@ -4,22 +4,22 @@ Nuxt provides an API to define the runtime config within your application and AP ## Exposing runtime config -To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your `nuxt.config` file, using either the [`privateRuntimeConfig` or `publicRuntimeConfig` options](/guide/directory-structure/nuxt.config#privateruntimeconfig) (based on whether you want it to be accessible on the client-side part of your app or not). +To expose config and environment variables to the rest of your app, you will need to define runtime configuration in your `nuxt.config` file, using either the [`runtimeConfig` options](/guide/directory-structure/nuxt.config#runtimeconfig) (based on whether you want it to be accessible on the client-side part of your app or not). **Example:** ```ts [nuxt.config.ts] export default defineNuxtConfig({ - publicRuntimeConfig: { - API_BASE: '/api' + runtimeConfig: { + API_SECRET: '123', // the private keys which should not be exposed to public + public: { + API_BASE: '/api', + } }, - privateRuntimeConfig: { - API_SECRET: '123' - } }) ``` -When adding `API_BASE` to the `publicRuntimeConfig`, Nuxt adds it to the pages' payload. This way we can universally access `API_BASE` in both server and browser. +When adding `API_BASE` to the `runtimeConfig.public`, Nuxt adds it to the pages' payload. This way we can universally access `API_BASE` in both server and browser. ### Environment Variables @@ -37,12 +37,12 @@ API_SECRET=api_secret_token ```ts [nuxt.config.ts] export default defineNuxtConfig({ - publicRuntimeConfig: { - BASE_URL: process.env.BASE_URL + runtimeConfig: { + API_SECRET: process.env.API_SECRET, + public: { + BASE_URL: process.env.BASE_URL, + } }, - privateRuntimeConfig: { - API_SECRET: process.env.API_SECRET - } }) ``` @@ -56,8 +56,8 @@ Within the Vue part of your Nuxt app, you will need to call `useRuntimeConfig()` **Note:** Behavior is different between client side and server side: -- On client side, only `publicRuntimeConfig` is available and the object is both writable and reactive. -- On server side, both `publicRuntimeConfig` and `privateRuntimeConfig` are merged and the object is read-only to avoid context sharing. +- On client side, only `runtimeConfig.public` is available and the object is both writable and reactive. +- On server side, both `runtimeConfig.public` and `runtimeConfig` are merged and the object is read-only to avoid context sharing. ```vue