Netlify deploy can't fetch API to Heroku backend

Viewed 354

Netlify frontend can't fetch API from Heroku backend. The Request URL adddress below is definitly not correct. How to make it correct?

In dev tool it shows this: Request URL: http://localhost:5000/api/castles

package.json frontend:"proxy": "http://127.0.0.1:5000/",

This is the link of Netlify: https://trusting-ride-8e237a.netlify.app/ Frontend code link : https://github.com/ZhiJuanTang/Castle_Frontend

This is the link of Heroku: https://castlebackend.herokuapp.com/api/castles Backernd code link: https://github.com/ZhiJuanTang/Castle_Backend

1 Answers

The frontend code relies on an environment variable to define the API endpoint:

const res = await fetch(`${process.env.REACT_APP_BLOG_API}/api/castles`);

Did you define REACT_APP_BLOG_API as an environment variable in Netlify? See Netlify Integration in the documentation.

Related