Combine Nodejs + React Native + Axios + CORS

后端 未结 1 1536
一个人的身影
一个人的身影 2021-01-21 03:46

I am trying to make a request to my API (Node.JS) from the front-end (react-native) using Axios. But I am confused about the error I get. Here\'s the print stack trace of the er

相关标签:
1条回答
  • 2021-01-21 04:38

    ANSWER :

    Alright, after few hours working on that bug, I found the answer by my self. The thing is that my server Node.js is running on my PC and I am testing my app with Expo on my cellphone. I was calling the server from the front-end with Axios with url http://localhost:3001/login. As I can't reach localhost of my PC with my cellphone, I had to change the url for the IP address of my PC, http://192.168.0.123:3001/login.

    Here's how to get your IP address of your PC : Calling locally hosted server from Expo App

    Here's a similar problem : Axios (in React-native) not calling server in localhost

    Hope it can help someone in the future with a similar bug.

    0 讨论(0)
提交回复
热议问题