Call expo.sendPushNotificationsAsync() with my back through a proxy

Hello guys !

I’m using expo-server-sdk-node and trying to send ExpoPushNotifications to mobile.
Due to interne politics, our backend can not reach an external server unless through our proxy.

So I need to use expo.sendPushNotificationsAsync(chunk) through proxy.
Is there any solution to instruct https://github.com/expo/expo-server-sdk-node/blob/master/src/ExpoClient.ts to use a proxy ?..

To resume the situation, the “normal” situation is :

  • Backend (using expo.sendPushNotificationsAsync()) ==request==> Expo Server.
    My situation right now :
  • Backend (using expo.sendPushNotificationsAsync()) ==request BLOCKED==> Expo Server.
    What I need due to interne politics :
  • Backend (using expo.sendPushNotificationsAsync()) ==Use my company proxy URI to pass the request ==> Expo Server

Thank you for your help !

The Expo constructor accepts an option named httpAgent that you can pass in like new Expo({ httpAgent: yourProxyAgent }). I haven’t tested this with a proxy but I believe you can pass in a standard Node.js https.Agent object as the httpAgent option.

Agents that conform to this interface (you could try https://github.com/TooTallNate/node-https-proxy-agent) are probably a good place to start.

new Expo({ httpAgent: 'https://myproxy.intranet:1234' })does not work… :frowning:

Getting as error :
TypeError [ERR_INVALID_ARG_TYPE]: The "options.agent" property must be one of type Agent-like Object, undefined, or false. Received type string.

Do you know if it’s possible or not to pass an httpAgent as argument ? It seems to only accept undefined or false.

you should read the github url that @ide linked to. you provided a string as your httpAgent, but as @ide said it needs to conform to the node https.Agent interface

1 Like

This is where the agent gets passed into node-fetch. Start here and debug to figure out the solution: https://github.com/expo/expo-server-sdk-node/blob/48cb6c139f9b2c7afd0ac80957039fc866b17f9a/src/ExpoClient.ts#L212-L217

Sorry for the missunderstanding.

I am now correctly using ressources given in the first reply :

let expo = new Expo({
  httpAgent: new HttpsProxyAgent({
    protocol: `https`,
    host: `proxy.intranet`,
    port: 1234,
  }),
});

I still get a strange error, that I can’t define if it is relative to Expo, our Proxy, or my code…

FetchError: request to https://exp.host/--/api/v2/push/send failed, reason: write EPROTO 4463953344:error:1
408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:
332:

    at ClientRequest.<anonymous> (/Users/users/Desktop/Workspace/node_modu
les/node-fetch/lib/index.js:1455:11)
    at ClientRequest.emit (events.js:203:13)
    at onerror (/Users/users/Desktop/Workspace/node_modules/https-proxy-ag
ent/node_modules/agent-base/dist/src/index.js:121:21)
    at callbackError (/Users/users/Desktop/Workspace/node_modules/https-pr
oxy-agent/node_modules/agent-base/dist/src/index.js:140:17)
    at processTicksAndRejections (internal/process/task_queues.js:85:5) {
  message: 'request to https://exp.host/--/api/v2/push/send failed, reason: write EPROTO 4463953344:error:1
408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:
332:\n',
  type: 'system',
  errno: 'EPROTO',
  code: 'EPROTO'
}

I tried with protocol: http and got this error :

message: 'request to https://exp.host/--/api/v2/push/send failed, reason: unable to verify the first certificate',

The version I used for https-proxy-agent is ^4.0.0, I tried to downgrade to ^3.0.0 but still the same both errors.

Please, do you have any idea ?
Thank you for your time and your help…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.