Search code examples
androidnode.jsexpresscorsapk

Nodejs backend can't be reached from apk


My nodejs backend is running on my personal server and can be reached from anywhere (I've tried from my smartphone, without being connected to my home network and it works). But when testing with the .apk built with eas, it does not work. It looks like my backend can't be reached from the apk itself, and I can't find any logs that could help me. It does not work when trying the .apk from an emulator neither. Is there anything specific to be configured to make it work?

I was thinking about a cors issue maybe...

Here is how cors is configured on my backend:

this.express.use(
  cors(
    {
      origin: true,
      credentials: true
    }
  )
);

Here is how requests are sent from the frontend:

const ApiManager = axios.create({
  baseURL: url, //public endpoint to my personal server
  responseType: 'json',
  withCredentials: true
});

If you have any idea... it would be awesome :)


Solution

  • You need to allow network permission for the apk to connect to your private server. To do this, you can add permissions to your AndroidManifest.xml file.

    <uses-permission android:name="android.permission.INTERNET" />
    

    Hope it helps you.