Next.js .env secrets base url keeps showing as localhost:3000

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

  1. mount the secrets on the dockerfile
  2. 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~

Ok so now from my understanding since this is a public secret in Next they public variables we can add them as arg variables in our docker file & I did so by this command:

npx dockerfile "--arg-build=NEXT_PUBLIC_BASE_URL:https:www.rleaguez.com/"

Then the deployment command was:

fly deploy --build-secret NEXT_PUBLIC_BASE_URL=https:www.rleaguez.com/

this section of the document was helpful: Next.js env public secrets fly.io help section

That doesn’t look like a valid URL.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.