Why NEXT.JS 14.01 now work with .env on server?

21 Views Asked by At

On my server, there is a route on the server-side page with an environment variable.

My all file: enter image description here

In docker its work:

example

app
  env_file: .env.prod

 db:
    env_file: .env.prod

I tried adding PUBLIC_NEXT_HOST= host to the variable HOST = host in my .env.prod and then accessing the page process.env.PUBLIC_NEXT_HOST but it doesn’t help

const res = await fetch(http://${process.env.NEXT_PUBLIC_HOST}/api/objects/);

But work only:

const res = await fetch(`http://90.100.100.99:3000/api/objects/`);

Page:

import "server-only"

async function getObjects() {
  try {
      const res = await fetch(`http://${process.env.NEXT_PUBLIC_HOST}/api/objects/`);
      if (res.ok) {
          return res.json();
      } else {
          throw new Error(`Error: ${res.status} ${res.statusText}`);
      }
  } catch (error) {
    
      console.error(error);
      return [];
  }
}


export default async function Home() {


  const objects = await getObjects();
0

There are 0 best solutions below