Relaying api call gets rejected because relaying server's url is not in api's certs

Viewed 33

I'm working on a api relay server that is supposed to log the requests and responses of api calls. Problem is when the server attempts to make an api call the api returns with status code 500 because the api's certs does not contain the relay server's url. I've made use of a https agent with options : {rejectUnauthorized: false} to bypass the authentication process. I saw that the host in the headers contains the server's url and I would like to know if I could modify the host to properly make authenticated api calls through the relay server.

Error when not using https agent:

Error [ERR_TLS_CERT_ALTNAME_INVALID]: Hostname/IP does not match certificate's altnames: Host: us-central1-apirelayserver.cloudfunctions.net. is not in the cert's altnames: DNS:*.company.services

API call:

const httpsAgent = new https.Agent({ rejectUnauthorized: false });
let headersJson = JSON.stringify(requestDocument.headers);
let axiosConfig = {headers: JSON.parse(headersJson),httpsAgent};
const info = await axios.post(requestDocument.apiBaseUrl.toString(),requestDocument.body,axiosConfig).catch(error => {
            console.log(error);
            console.log(error.response.body);
        });
response.status(200).send(info.data);
0 Answers
Related