Search code examples
expressherokuhttp-post

sending request to an APIwhen the app is online


This is my first time to deploy a website online so I'm confused about a certain thing. Making requests to an API that is. I have my own express server to which I send some data and it sends response. I have this line of code on client side which I'm not sure how to handle:

const res = await axios.post('http://localhost:5000/upload', formdata)

How should I modify the URL so that client connects to the server and gets some information back?(I'm using heroku to deploy the website)


Solution

  • This is very straightforward, first get the URL of the deployed heroku apps.

    By default, a Heroku app is available at its Heroku domain, which has the form [name of app].herokuapp.com. For example, an app named serene-example-4269 is hosted at serene-example-4269.herokuapp.com.

    So you for the example above, just change the code to

    const res = await axios.post('http://serene-example-4269.herokuapp.com/upload', formdata)