I am deploying a Next app and when trying to obtain a value from the .env file it’s either undefined or it reads the wrong value of http://localhost:3000
In the .env file it’s defined as:
NEXT_PUBLIC_BASE_URL=https:www.rleaguez.com/
I have it defined in the fly.io webpage admin in secrets with name & value;
in my local terminal if I use flyctl secrets list I can view the secret listed;
I have seen this help page Fly.io build secrets which states we need to
- mount the secrets on the dockerfile
- provide the value when fly deploy
In the docker file there is this section where it’s mounted:
# Build application
RUN --mount=type=secret,id=NEXT_PUBLIC_BASE_URL \
NEXT_PUBLIC_BASE_URL="$(cat /run/secrets/NEXT_PUBLIC_BASE_URL)" \
yarn run build
then when I deploy in terminal I use:
fly deploy \
--build-secret NEXT_PUBLIC_BASE_URL="https:www.rleaguez.com/"
(this deploy seems to be much faster than a normal deploy with out the secret;)
In the page I placed a simple console log to view the value in the browser such as
console.log("process.env.NEXT_PUBLIC_BASE_URL === ", process.env.NEXT_PUBLIC_BASE_URL);
But what occurs is that the value of the secret is stuck on “http://localhost:3000” not the production value which should be “https:www.rleaguez.com/”
If you want to see the console log the page is here: [Page with console log localhost](https://www.rleaguez.com/organizationz/create)
What needs to be done differently to get the correct secret value in this Next.js app on fly.io?
Thanks in advance for any & all feedback~