Tamjid
Tamjid

Reputation: 5526

React build fetch requests failing

Mine react apps fetch requests work fine when I test in dev environment (npm start) but after creating a build package (npm run build) and then running that, all my fetch requests receive a failed status when making requests to my locally hosted API. Could this be because my API is not https? Any other ideas?

Thanks

Upvotes: 1

Views: 1087

Answers (2)

Aakash Jha
Aakash Jha

Reputation: 40

Try adding a proxy field in the package.json of your react app. Once that is in place, run build and test. This usually solves the api issue that react can have with api.

package.json: proxy: "http://localhost:8000"

requests in React app: fetch('/api/urls/....')

Upvotes: 0

Icaruk
Icaruk

Reputation: 902

Double check if you have the REACT_APP_API_URL on your .env files:

  • .env (it should be localhost)
  • .env.production (this is used on build, it should be production URL)

Upvotes: 0

Related Questions