Active React application does not connect to Node.js server on my laptop

Asked

Viewed 1,193 times

0

I’m developing an app in React Native, using the expo.

I have a Node.js API running on my Macbook. Both my phone and laptop are under the same Wifi network.

In the app, I have an API call pointing to the IP of my machine + port where the server is running:

import axios from 'axios';

const api = axios.create({
    baseURL: 'http://<IP da máquina>:3333'
});

export default api;

The API call is made in:

const response = await api.get('resource')

however, when I start the application, the data that should come from my Node.js server is not loaded.

Trying to access the same endpoint in the mobile browser, I get error:

ERR_ADDRESS_UNREACHABLE

I have tried several ways to solve the problem: - I disabled the Machine Firewall - I checked that the router configuration 'Isolation ap' was enabled, and was not. - among other things.

1 answer

0

For security reasons, on the newer Android and IOS systems, requests are blocked http on account that it is not a secure protocol and allows only https.

  • With https also did not work :c

  • Android has another security mechanism against security certificates known as Self Signed Certificate in which it is a lock to prevent the host from generating a custom certificate signed by itself, thus allowing the famous Attack as the man-in-the-middle. If you want to know, see this guide here: https://developer.android.com/training/articles/security-ssl To solve your problem you would have to host your code on some server with the HTTPS Secure certificate.

  • Man, thanks for the info! Too bad I need to do all this just to test a simple app... I’ll make sure there’s no way to pass this lock

  • it is possible to use a version of the old android, in which did not yet have this security mechanism, although only recommend it for local environment.

  • Do you have more details about this? Oh yes, your information was correct. I climbed the API in Heroku just to test, and actually using https:// I was able to connect c the back. Put this as an answer, so I score her.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.