I've been trying to make an API call using axios and node-fetch and the end point needs to be connected via a proxy and also needs certs. below is what I'm trying to do
import axios from "axios";
import { getPrefetchedSSLConfig } from "./get-ssl-certs";
import HttpsProxyAgent from "https-proxy-agent";
import https from "https";
const callEndPoint = () => {
axios.defaults.baseURL = "https://api.endpoint.com";
const sslInfo = getPrefetchedSSLConfig();
let httpsAgent = new HttpsProxyAgent({
host: proxy.hostname,
port: proxy.port,
rejectUnauthorized: false,
ca: sslInfo.ca,
});
return axios({
proxy: false,
method: "GET",
url: `/v1/api/endpoint`,
responseType: "json",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
},
httpsAgent,
}).then((res) => {
return {
data: res.data,
status: res.status,
};
});
};
export default callEndPoint;
I've also tried the options mentioned here and also tried node-fetch too.
I'm not sure if I'm missing something obvious or something I should know that I don't.