skip to Main Content

I have built & deployed my ReactJs and NestJs on the same server on different ports. Reactjs is running in port 3000 and Backend API is running in port 3001.

In the env file of the ReactJs, I have set http://localhost:3001/ as my backend API URL.

Now the problem is if I do run the backend API service from my PC from port 3001. Then the Deployed ReactJs in the production server does fetch the API from my PC’s localhost:3001 instead of my production server’s localhost:3001.

2

Answers


  1. You shouldn’t hardcoded the port of the API endpoint, otherwise it will always point to the local machine where the browser is running.

    In your production environment, set the environment variable to the correct URL of your backend API instead.

    Login or Signup to reply.
  2. the API URL localhost:3001 is only accessible to your device and it an not accessed by your production server, you need to host your back-end somewhere. then setup the server and proxy there in order to access the APIs on production server

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search