Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Allow runtime environment variables in middleware #36326

Closed
jordie23 opened this issue Apr 20, 2022 · 0 comments
Closed

Allow runtime environment variables in middleware #36326

jordie23 opened this issue Apr 20, 2022 · 0 comments

Comments

@jordie23
Copy link

jordie23 commented Apr 20, 2022

Describe the feature you'd like to request

We'd like the ability to use environment variables at runtime in middleware.

It is a common application practice to build & bundle an app once and then configure it based on runtime environment variables. This allows us to adhere to being a 12 factor app as much as possible. We can do this with the rest of nextjs, but not middleware.

Describe the solution you'd like

I'm unsure what the mechanism should be because you currently replace process.env.FOO at build time, but there should be some ability to read it. Perhaps make serverRuntimeConfig specially available in middleware? Perhaps make certain env vars available if they're prefixed with MIDDLEWARE_ like the established pattern for prefixing PUBLIC_ vars ?

Describe alternatives you've considered

We previously were able to use optional chaining to get around this and process.env?.FOO worked at runtime in middleware, but as there were changes at some point between nextjs versions this ability has disappeared and there appears to be no way to access any environment variables at run time.

The only other solution we can think of is mentioned here to perhaps load a JSON file at deployment time with config that would be included in the app, but it is somewhat awkward to use and requires changes to the way env vars are set by deployment systems and generally doesn't feel right. It'd be better if environment variables functioned as they do in other parts of the application.

@vercel vercel locked and limited conversation to collaborators Apr 21, 2022
@timneutkens timneutkens converted this issue into discussion #36338 Apr 21, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant