#env variable is undefined in server side

5 messages · Page 1 of 1 (latest)

last hollow
#

Hi i need help in getServerSideProps :

export async function getServerSideProps({ locale, query }) {
  console.log(process.env.URL_API_GATEWAY); // this logs well https://...
  try {
    const response = await fetch(`${process.env.URL_API_GATEWAY}/article/v1/articles/${query.id}`); this returns undefined 
    if (!response.ok) {
      throw new Error("Failed to fetch.");
    }
    const item = await response.json();
    return {
      props: {
        item,
        ...(await serverSideTranslations(locale, ["common", "supply", "api"])),
      },
    };
  } catch (error) {
    console.error("Error fetching data:", error);
    return {
      props: {
        item: null,
        ...(await serverSideTranslations(locale, ["common", "supply", "api"])),
      },
    };
  }
}

So env variable logs but i can't use it in fetch method,
what kind of problem this seems to be ?

tiny lavaBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

errant bay
#

You should define env variable in a below way as well as .env file should be located in your project's root directory.
URL_API_GATEWAY=your key
thats it!

last hollow
#

SOLVED,
true it the / that i added twice in the url, thx