Runtime Config
Warning: This feature is considered legacy and does not work with Automatic Static Optimization, Output File Tracing, or React Server Components. Please use environment variables instead to avoid initialization overhead.
To add runtime configuration to your app, open next.config.js
and add the publicRuntimeConfig
and serverRuntimeConfig
configs:
Place any server-only runtime config under serverRuntimeConfig
.
Anything accessible to both client and server-side code should be under publicRuntimeConfig
.
A page that relies on
publicRuntimeConfig
must usegetInitialProps
orgetServerSideProps
or your application must have a Custom App withgetInitialProps
to opt-out of Automatic Static Optimization. Runtime configuration won't be available to any page (or component in a page) without being server-side rendered.
To get access to the runtime configs in your app use next/config
, like so: