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

Issues connecting behind a corporate proxy #35

Closed
stefan-THD opened this issue Sep 25, 2017 · 10 comments
Closed

Issues connecting behind a corporate proxy #35

stefan-THD opened this issue Sep 25, 2017 · 10 comments

Comments

@stefan-THD
Copy link

We are having issues getting this package to work with our enterprise proxy settings, is it possible to configure the https get method in resource.js to accept proxy settings?

@stefan-THD stefan-THD changed the title Issues connecting behing a corporate proxy Issues connecting behind a corporate proxy Sep 25, 2017
@spirosikmd
Copy link
Contributor

Hi @stefan-THD! Thank you for submitting this issue! Can you please provide a reproducible example? That would help a lot!

@stefan-THD
Copy link
Author

stefan-THD commented Oct 4, 2017

Thanks spirosikmd, our company uses a proxy, which requires us to add additional options with the http request, but the default plugin doesn't allow to send in options to the http request.

var Usabilla = require("usabilla-api");
var usabilla = new Usabilla(process.env.USABILLA_ACCESS_KEY, process.env.USABILLA_SECRET_KEY);
let buttonFeedbackQuery = {
  "id": "############",
  "params": {
    "limit": "500"
  }
};
function saveUsabillaInfo() {
    usabilla.websites.buttons.feedback.get(buttonFeedbackQuery).then(feedback => {
        console.log(JSON.stringify(feedback));
    }
}

saveUsabillaInfo();

Would give us a connection timeout error because it wasn't get through our proxy. This is what we end up doing:

var Usabilla = require("usabilla-api");
var http = require('http');
var usabilla = new Usabilla(process.env.USABILLA_ACCESS_KEY, process.env.USABILLA_SECRET_KEY);

function saveUsabillaInfo() {
  var proxy = process.env.HTTP_PROXY;
  var proxySplit = proxy.split(':');
  var proxyServer = proxySplit[1].replace('//', '');
  var proxyPort = proxySplit[2];
  var date = new Date();
  date.setDate(date.getDate() - 120);
  date.setHours(0);
  date.setMinutes(0);
  date.setSeconds(0);

  var since = Math.round(date.getTime());

  let buttonFeedbackQuery = {
    "id": "############",
    "params": {
      "limit": "500"
    }
  };

  usabilla.websites.buttons.feedback.get(buttonFeedbackQuery);
  var signingFactory = usabilla.websites.buttons.signatureFactory;
  var signature = signingFactory.sign();
  var signedHeader = signature.headers;

  var options = {
    protocol: 'http:',
    host: proxyServer,
    port: proxyPort,
    path: '/live/websites/button/9c7cb92f1d37/feedback?since=' + since,
    headers: {
      'x-ub-api-client': signedHeader['x-ub-api-client'],
      'x-usbl-date': signedHeader['x-usbl-date'],
      host: 'data.usabilla.com',
      Authorization: signedHeader.Authorization
    }
  }


  http.get(options, function (response) {
    //PROCESS RESPONSE 
  });

}

saveUsabillaInfo();

We were able to remedy this by using the usabilla plugin to get the signatures and adding them to our own http request so that we could pass in our own options. It is not ideal because we have to use the usabilla plugin to send a bad proxy-less http request so we can get the signature.headers and then add them to our own request using the http module. It would be nicer if the usabilla get() method allowed for us to send the options as a parameter like we would normally be able to send with the built in http module.

@spirosikmd
Copy link
Contributor

spirosikmd commented Oct 4, 2017

Thank you for the detailed information @stefan-THD! So if I understood well, you basically want to configure the protocol, host, and port? Currently, there is no way to configure the package to override these values.

If you could do something like the following

const Usabilla = require('usabilla-api');

const proxy = process.env.HTTP_PROXY;
const proxySplit = proxy.split(':');
const proxyServer = proxySplit[1].replace('//', '');
const proxyPort = proxySplit[2];

const usabilla = new Usabilla(
  process.env.USABILLA_ACCESS_KEY,
  process.env.USABILLA_SECRET_KEY,
  {
    protocol: 'http:',
    host: proxyServer,
    port: proxyPort,
  }
);

usabilla.websites.buttons.feedback.get(/* query here */);

would it work for you? Then, we can consider adding support for overriding protocol, host, and port.

@stefan-THD
Copy link
Author

stefan-THD commented Oct 4, 2017

@spirosikmd Yes! Something along those lines should work well for us, as long as we can set those options.

@spirosikmd
Copy link
Contributor

Hi @stefan-THD! You should be able to configure client in v1.1.0!

@stefan-THD
Copy link
Author

We were able to try it out, apparently, even you set the protocol to http, https will still send it as https. Is there a way to use http instead of https?

@stefan-THD
Copy link
Author

@spirosikmd Is there a way to use http instead of https yet?

@spirosikmd spirosikmd reopened this Oct 20, 2017
@spirosikmd
Copy link
Contributor

Hi @stefan-THD! It is true, by default the https package uses the https protocol. I haven't looked at it yet. I guess it is possible to use the http package, when someone specifies the http protocol through the config.

@spirosikmd
Copy link
Contributor

Hi @stefan-THD! There is a new release v1.1.1, which should fix the http client issue!

@stefan-THD
Copy link
Author

Thanks so much! We will check it out.

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

2 participants