Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETIMEDOUT in sendNotification.Can it add a proxy option? #280

Closed
lowesyang opened this issue May 22, 2017 · 13 comments
Closed

ETIMEDOUT in sendNotification.Can it add a proxy option? #280

lowesyang opened this issue May 22, 2017 · 13 comments

Comments

@lowesyang
Copy link

I've already used webpush.sendNotification and it automatically request the Google server address.But I received so many ETIMEDOUT.
image

For the server in China, the network is unluckily blocked by gov, so we have to use proxy server to link websites abroad.

Hope the web-push can add proxy options.

@marco-c
Copy link
Member

marco-c commented Jun 4, 2017

What options would you need?

@lowesyang
Copy link
Author

Like

const options={
  ...,
  proxy:"http://xxx.xxx.xxx"  // my proxy server
}
webpush.sendNotification(
  pushSubscription,
  payload,
  options
);

So that the web-push can request the google url through my proxy server.

@marco-c
Copy link
Member

marco-c commented Jun 5, 2017

I'd happily accept a pull request for this.

You can also implement the same without using a standard proxy. Just change the endpoint URL to be the URL of your custom proxy (e.g. YOUR_PROXY_URL?endpoint=ACTUAL_ENDPOINT_URL) and make the proxy send the request to the endpoint URL.

@lowesyang
Copy link
Author

Oh,that's a good idea~ But actually the proxy server is not mine, and i can do nothing on it to build such custom api.
A pr can be ok~
Thanks for replying.

@lowesyang
Copy link
Author

Hey due. I've forked your repo and add proxy api. But after serious consideration, i think it's not necessary to pull request. There are three reasons:

  • The demand of proxy is just for Chinese developers, so this api will be very duplicate for other people.
  • The original code can not be run in my local environment for some reasons, so I can't do automatic test.
  • For convenience I only change https to http to request the Push Server using proxy, and it works in my project.

So it's better to make it an independent repo, and this is the link

@martijndwars
Copy link
Member

martijndwars commented Jun 17, 2017

Note that it's not only Chinese developers that are affected by this problem. If you are behind a corporate proxy, which is common in big organisations, you encounter the same issue. Having the ability to set a proxy, or better, respecting the HTTP(S)_PROXY environment variables, would benefit these users. That said, #282 provides exactly this functionality, so I think the focus should be on integrating that PR. Just my two cents!

@lowesyang
Copy link
Author

lowesyang commented Jun 17, 2017

Oh. I have not noticed that PR. It's really good if the official lib implements that API. Thanks for contributing!!

@Peanoquio
Copy link

Hi there,
Pardon me for posting this late since this topic has already been up for a few months.
Just to confirm, does this mean that the web push library cannot work behind a corporate proxy??
Thank you in advance.

@marco-c
Copy link
Member

marco-c commented Jan 29, 2018

I think so, until #282 is finished up and merged.

@Peanoquio
Copy link

Thank for the update regarding this.
Have a great week ahead!

@anasameur
Copy link

I hacked the library to be able to bypass this issue of proxy here are the changes that I brought to the library

const HttpsProxyAgent = require('https-proxy-agent');
var proxy = <Your_proxy_address>;
var agent = new HttpsProxyAgent(proxy);
......
WebPushLib.prototype.sendNotification =
function(subscription, payload, options) {
let requestDetails;
try {
requestDetails = this.generateRequestDetails(
subscription, payload, options);
} catch (err) {
return Promise.reject(err);
}

    return new Promise(function(resolve, reject) {
        const httpsOptions = {};
        const urlParts = url.parse(requestDetails.endpoint);
        httpsOptions.hostname = urlParts.hostname;
        httpsOptions.port = urlParts.port;
        httpsOptions.path = urlParts.path;

        httpsOptions.headers = requestDetails.headers;
        httpsOptions.method = requestDetails.method;
        httpsOptions.agent = agent 
        ............

i just use https-proxy-agent module

this solution will just work behind proxy server , now i'm trying to report changes that will make the module function whether you're behind a proxy or not

@marco-c
Copy link
Member

marco-c commented Feb 6, 2018

@anasameur if you want, you can pick up the already existing PR (#282) and finish it.

@marco-c
Copy link
Member

marco-c commented Mar 29, 2018

Fixed by #319.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants