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
yyh1102 opened this issue May 22, 2017 · 13 comments
Closed

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

yyh1102 opened this issue May 22, 2017 · 13 comments

Comments

@yyh1102
Copy link

@yyh1102 yyh1102 commented May 22, 2017

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

This comment has been minimized.

Copy link
Member

@marco-c marco-c commented Jun 4, 2017

What options would you need?

@yyh1102

This comment has been minimized.

Copy link
Author

@yyh1102 yyh1102 commented Jun 5, 2017

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

This comment has been minimized.

Copy link
Member

@marco-c 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.

@yyh1102

This comment has been minimized.

Copy link
Author

@yyh1102 yyh1102 commented Jun 5, 2017

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.

@yyh1102

This comment has been minimized.

Copy link
Author

@yyh1102 yyh1102 commented Jun 16, 2017

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

This comment has been minimized.

Copy link
Member

@MartijnDwars 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!

@yyh1102

This comment has been minimized.

Copy link
Author

@yyh1102 yyh1102 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

This comment has been minimized.

Copy link

@Peanoquio Peanoquio commented Jan 29, 2018

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

This comment has been minimized.

Copy link
Member

@marco-c marco-c commented Jan 29, 2018

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

@Peanoquio

This comment has been minimized.

Copy link

@Peanoquio Peanoquio commented Jan 29, 2018

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

@anasameur

This comment has been minimized.

Copy link

@anasameur anasameur commented Feb 6, 2018

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

This comment has been minimized.

Copy link
Member

@marco-c marco-c commented Feb 6, 2018

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

@marco-c

This comment has been minimized.

Copy link
Member

@marco-c 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
Projects
None yet
5 participants
You can’t perform that action at this time.