Reputation: 415
Going to deploy an application on heroku. I have got requests from react-axios that calls to localhost
. Now I know that when I deploy it to a server, localhost
refers to server address.
So how do I change these localhost
to IP assigned by Heroku.
Here is an example of axios call from react
axios.get("http://localhost:5000/getMessages").then((response) => {
this.setState({ res: response.data });
}
Upvotes: 1
Views: 3617
Reputation: 8253
Change:
axios.get("http://localhost:5000/getMessages")
to:
axios.get("/getMessages")
Upvotes: 3
Reputation: 1278
Since you are hosting your app on heroku, and you are calling your API that is on the same domain, you can use window.location.hostname
axios.get('${window.location.hostname}:5000/getMessages').then((response) => {
this.setState({ res: response.data });
}
Upvotes: 1