tradle / rn-nodeify

hack to allow react-native projects to use node core modules, and npm modules that use them
MIT License
614 stars 114 forks source link

https module doesn't seems to be working properly #137

Open bsumer-wyn opened 5 months ago

bsumer-wyn commented 5 months ago

Hi, I have shimmed https and https modules, and when I try to create a new httpsAgent, it returns an empty object. I wonder what I am doing wrong. What I am trying to do is basically passing my ssl certificate and private key to the httpsAgent so I can be authenticated in the server without using a VPN client. Help would be greatly appreciated. Thanks

const httpsAgent = new https.Agent({
  cert: cert2,
  key: key2,
  rejectUnauthorized: false,
});
console.log("AGENT", httpsAgent);

This is my dependencies:


  "react-native": {
    "https": "https-browserify",
    "http": "@tradle/react-native-http"
  },
  "browser": {
    "https": "https-browserify",
    "http": "@tradle/react-native-http"
  }

My shim file:

if (typeof __dirname === 'undefined') global.__dirname = '/';
if (typeof __filename === 'undefined') global.__filename = '';
if (typeof process === 'undefined') {
  global.process = require('process');
} else {
  const bProcess = require('process');
  for (var p in bProcess) {
    if (!(p in process)) {
      process[p] = bProcess[p];
    }
  }
}

process.browser = false;
if (typeof Buffer === 'undefined') global.Buffer = require('buffer').Buffer;

// global.location = global.location || { port: 80 }
const isDev = typeof __DEV__ === 'boolean' && __DEV__;
process.env.NODE_ENV = isDev ? 'development' : 'production';
if (typeof localStorage !== 'undefined') {
  localStorage.debug = isDev ? '*' : '';
}

// If using the crypto shim, uncomment the following line to ensure
// crypto is loaded first, so it can populate global.crypto
// require('crypto')
Braudin commented 5 months ago

Me sumo a esta pregunta

Shahanshah-TA commented 2 weeks ago

Hi @bsumer-wyn did you find any solution for this?

Shahanshah-TA commented 2 weeks ago

@brysgo @mvayngrib @spwilko @pgmemk

mvayngrib commented 6 days ago

hey guys, the implementation for this comes from react-native-http, which is a tiny adaptation on top of http-browserify, which doesn't support http.Agent https://github.com/browserify/http-browserify/blob/17b2990010ebd39461d1117c1e2c50c25eab869f/index.js#L49

it's probably possible to implement in react native, unlike in the browser, but it's not something i'll be able to do personally. PRs welcome to react-native-http :)