1

I'm making a simple request using the request-promise library, but it errors out because I have a self-signed cert in my chain (which is a requirement, not having it is not an option)

with NPM I can specify that cert to install packages (which I've done):

npm config set cafile "<path to my certificate file>"

then I can install whatever packages becuase it knows to trust my self-signed cert.

Is there a way to make a request with request-promise and specify the self-signed cert to trust?

The request is very straightforward: return request.get('/myendpoint')

It just throws an error because of the self-signed cert.

If it's not possible with request-promise is there another library that allows that kind of functionality?

1 Answer 1

1

Since request-promise is a wrapper around the request library (which in itself is a wrapper around the native http module), you can add the following option to the request parameters:

const rp = require('request-promise');

const agentOptions = {
  host: 'www.example.com'
, port: '443'
, path: '/'
, rejectUnauthorized: false
};

const agent = new https.Agent(agentOptions);

rp({
  url: "https://www.example.com/api/endpoint",
  method: 'GET',
  agent: agent
}).then(...);

Based off of the http.request documentation.

Sign up to request clarification or add additional context in comments.

2 Comments

I see that I can specify a cert within the agentOptions - so I can just do as you've outlined here, great! Thanks!
I don't get it. where is the usage of the certificate?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.