PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 21, 2022

[FIXED] How do I set environment variables to Next.js (SSR) after it is built?

 August 21, 2022     docker, environment-variables, next.js     No comments   

Issue

I have this Next.js app (using SSR, using next start) which communicates with a server externally, and the server URL would have to be dynamic. This information, among other things, are dynamic variables that I would probably only have after initial deployment.

I have currently dockerized this Next.js app, so it gets built, then pushed to Docker Hub.

The "happy-flow" for the end user who would be using my app is that they should be able to pull the docker image of the prebuilt frontend, pass an env_file through docker-compose and just be able to use it as they wish.

All the examples (this and this) I've seen have explained how to pass ENV to Next.js but the ENV has to be passed during build time, which defeats the purpose of portability.


Solution

I was able to resolve this issue by making use of this package (react-env), which isn't the most ideal solution but works for now.

It has a couple of setup steps and opinionated configuration to it, but works as expected for anyone who's looking for a solution to pass env vars after the Next.js app has been built.



Answered By - Amruth Pillai
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing