Eneris / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
16 stars 15 forks source link

feat: add `axiosProxyConfig` option to the configuration #5

Closed erikian closed 1 year ago

erikian commented 1 year ago

Not sure if you accept PRs here, but since I had to fork this project to add a feature I need, I thought to contribute back.

This allows users to specify the proxy options to be passed to axios when doing FCM/GCM requests:

const instance = new PushReceiver({
  axiosProxyConfig: {
    proxy: {
      protocol: 'http',
      host: 'somehost',
      port: 1234,
      auth: {
        username: 'foo',
        password: 'bar',
      },
    },
  },
  // ...other options
})

I also fixed the signatures for the doRegister and postRegister functions.

Eneris commented 1 year ago

Thanks. I'll check it out :)

Eneris commented 1 year ago

Looks good. Just one thing: Could be nice to allow to override other axios options too if desired.

const instance = new PushReceiver({
  axios: {
    proxy: {
      protocol: 'http',
      host: 'somehost',
      port: 1234,
      auth: {
        username: 'foo',
        password: 'bar',
      },
    },
    // ...other axios options
  },
  // ...other options
})
erikian commented 1 year ago

I actually had this initially:

    axiosConfig?: Omit<
      AxiosRequestConfig,
      'url' | 'method' | 'headers' | 'data' | 'responseType'
    >

This would prevent users from passing in options that shouldn't be overridden (well, as long as Typescript is used as intended). What do you think?

erikian commented 1 year ago

I've changed it to axiosConfig and placed it before the options that shouldn't be overridden.

Eneris commented 1 year ago

Sounds perfect. Thanks. I'll do some short testing and merge it.