-
Notifications
You must be signed in to change notification settings - Fork 28k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to serve env for frontend in runtime with docker #77448
Comments
for any one wondering how to do it with runtime.
and pass it in runtime with -e SECRET_TOKEN=2332 etc. This is the onyl way it seems to work for envs that are used in frontend but no need to worry about envs that are being used in server components. Also open to any other good suggestions |
I wouldn't recommend using secrets or anything sensitive on the front-end. To add to this, I've recently done some work on an app that required us to have a single docker image for all environments, and have the container created from the image with different sets of environment variables (think different api urls, different auth login urls). Next.js is lacking some documentation about WHERE specifically you can use runtime environment variables versus when the app interpolated environment variables from the build environment will be baked into the code/docker image. This is what I found:
Having said all this, I just moved my rewrites and custom CSP to some middlewares and then served anything non-sensitive the front-end needed from an This allowed me to move away from having to rely on NEXT_PUBLIC_ environment variables that get interpolated into the client code/docker images when the app is built, allowing me to build once and deploy anywhere. |
Link to the code that reproduces this issue
https://github.com/ebharathi/nextauth-prisma-graphql
To Reproduce
Documentation only provides steps to embed env in build time rather than run time which is not ideal
This is an issue i have been facing for a long time now. I know it can be solved by running bash to replace a string with env. But this just makes the use of NEXT_PUBLIC_envs not useful ? i mean whats the purpose if we could do it in dev but not in prod using docker.
Current vs. Expected behavior
current: frontend envs are served during only build time with docker
expected: allow envs for frontend in runtime with docker
Provide environment information
Which area(s) are affected? (Select all that apply)
Runtime
Which stage(s) are affected? (Select all that apply)
Other (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: