0

I've got two separate apps (frontend and backend) running on heroku. Let's say frontend can be accessed through http://frontend-app.url and backend through http://backend-app.url The front end app runs on node.js using express. I want my frontend app to call backend app api, but I can't make it call anything other than the same domain that frontend is deployed.

In server.js i got the following lines, which supposedly should reroute the api calls.

app.get('/data', (req, res) => {
    res.json({url: 'http://backend-app.url'})
});

All api urls start with /data. I start my app by node server.js. First call when accessing the frontend app is always /data/units, but it always calls http://frontend-app.url/data/units instead of http://backend-app.url/data/units.

How do I make this right?

Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
eight
  • 339
  • 1
  • 5
  • 16
  • 1
    `res.json` does not reroute. It simply converts the response to JSON and sends it back. See [res.json](https://expressjs.com/en/api.html#res.json). Have you looked at [res.redirect](https://expressjs.com/en/api.html#res.redirect) ? – Mayur Dec 30 '18 at 15:32
  • Did some more research after looking into Mayur's comment and found the answer on a different SO question. So marking this as duplicate. – eight Dec 30 '18 at 15:53

0 Answers0