10
votes

Is possible use HTTPS Agent in React Native app?

My code right now is:

import axios from 'axios';
import ip from './ip';

import https from 'https';

const httpsAgent = new https.Agent({rejectUnauthorized: false});

const api = axios.create({
    baseURL: `${ip}/api`,
    httpsAgent,
});

export default api;

But show the follow Error:

ExceptionsManager.js:76 Error: InternalError Metro has encountered an error: While trying to resolve module https from file /mobile/src/services/api.js, the package /mobile/node_modules/https/package.json was successfully found. However, this package itself specifies a main module field that could not be resolved (/mobile/node_modules/https/index.js. Indeed, none of these files exist:

  • /mobile/node_modules/https/index.js(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  • /mobile/node_modules/https/index.js/index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
1
The ip.js imported file at line 2, export a const with the IP value how: "https:// IP_AWS"Mateus Alves de Oliveira
Did you found any solution?Pinki Dhakad
did you found solution? same issue me too.Punita
Did you found any solution?Hasan Can Buyukasik
Any solution yet?Matthias

1 Answers

-1
votes

I found the follow solution: I did create an account for my DNS (fretec.app) hosting to the AWS instance IP. After this, I did configure my remote API with the Nginx and Certbot at AWS instance. Then, the Axios on frontend can access the API with HTTPS normally, without HTTPS Agent.

I use this tutorial for deploy a Node API at AWS:

  1. https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04-pt

  2. https://www.digitalocean.com/community/tutorials/como-proteger-o-nginx-com-o-let-s-encrypt-no-ubuntu-18-04-pt