'React request to wrong endpoint

my react app is running on www.frontend.com it makes an API request to the backend server https://backend.com.

I opened the network tab in developers tools, it's making a request to forntend.com/undefined instead of backend.com.

in .env

API_URL='https://backend.com'
const endpoint = process.env.API_URL
const client = new GraphQLClient(endpoint)

dockerfile

FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY .env ./
RUN npm install env-cmd -g --silent
RUN env-cmd -f .env npm install --silent
RUN env-cmd -f .env npm install [email protected] -g --silent
COPY . ./
RUN env-cmd -f .env npm run build

What are the possible reasons for this?



Solution 1:[1]

Do you restarted the environment after you added the API_URL inside the .env? Normally it returns undefined when the Node.js does not detect a newly variable. Try to restart.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anti-duhring