0

I want to make simple get request to my API deployed to Heroku. Here is how:

axios.get(my_url_here).then(res => this.topics = res.data).catch(e => {
         print(JSON.stringify(e)); 
     }); 

But, only catch works and it prints following:

{"message":"Network Error","name":"Error","stack":"Error: Network Error\n at createError (webpack-internal:///./node_modules/axios/lib/core/createError.js:16:15)\n at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axios/lib/adapters/xhr.js:83:14)","config":{"url":"my_url_here","method":"get","headers":{"Accept":"application/json, text/plain, */*"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1}}

That error does not say anything. I couldn't find good materials about it, but some of them tells that it is a problem related to cors. I don't have any code related to Allow-origin stuff on my API, but how the web browser successfully makes requests? And why axios fails and cannot make that requests? I tried to use cors library on my server-side but when I deployed code to Heroku, it just stopped working. What can be the reason for above error and how to solve it?

neo
  • 1,314
  • 2
  • 14
  • 34
  • Have you tried pinging `my_url_here` and see if your server is alive and returns packets? – Naor Levi Jan 19 '20 at 11:41
  • It is absolutely alive. Because, I can make get requests via browser or Postman. It works. I don't know why it fails with axios. – neo Jan 19 '20 at 11:44
  • 1
    It must be a CORS issue. Postman doesn't do the preflight request that's why you get the response. Are you using express for your server? can you put your code here? – Ashish Modi Jan 19 '20 at 11:57
  • Yes, I use express. It is simple get request. Any cors stuff not configured. Can you send some link about how to configured it properly? – neo Jan 19 '20 at 13:28
  • Does this answer your question? [React: Axios Network Error](https://stackoverflow.com/questions/45980173/react-axios-network-error) – user2222 Jan 19 '20 at 14:33

0 Answers0