Next.js Discord

Discord Forum

How to expose env vars to middleware when running next app in Docker

Answered
Bonga shad posted this in #help-forum
Open in Discord
Bonga shadOP
I want to access .env.local file variables in middleware for auth purposes. It seems like the env var is not available? How can I set this in my dockerfile?
Answered by Bonga shad
I have fixed that by loading.env file through docker compose yaml. It was required for runtime environment.
View full answer

5 Replies

@Bonga shad I want to access .env.local file variables in middleware for auth purposes. It seems like the env var is not available? How can I set this in my dockerfile?
If its in production, I think you should just use .env.

And I'm not sure if thats expected. Can you try renaming file to .env, and use docker to create a production server, and see if it works?
Bonga shadOP
I have fixed that by loading.env file through docker compose yaml. It was required for runtime environment.
Answer
Bonga shadOP
@"use php" how do I do that?
Original message was deleted
Refer to this message