I'm facing a frustrating issue with my project in server mode. We need to pass environment variables at runtime and access them on both the server and client side.
Following the publicRuntimeConfig
method from the documentation, everything works fine when running in dev mode (yarn dev
). However, after building the project and deploying it in Docker or Kubernetes, the functionality breaks.
Here is a snippet of the code:
const nextConfig = {
publicRuntimeConfig: {
PARAM_A: process.env.PARAM_A || "defaultA",
PARAM_B: process.env.PARAM_B || "defaultB"
}
};
module.exports = nextConfig;
In addition, _app.tsx
, index.tsx
, otherpage.tsx
, and help.tsx
files contain similar logic for accessing these variables.
The issue arises when moving from the first page to subsequent pages, as the environment variables are not being passed correctly. I want these values to be accessible throughout the entire application. Any guidance on what might be going wrong would be greatly appreciated.