Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

673
Visualizações
How can I send a self-signed certificate through axios in the browser?

I am working on a create-react-app that queries an API that requires a self-signed certificate to validate the request. I am grabbing the certificate through a GET request and using a helper to create a new Agent. My initial solution was to assign the httpsAgent in axios.interceptor to attach the certificate to every axios call.

But from what I understand the httpsAgent object is not being passed correctly to index.js because index.js runs in the browser and https is a core node module.

Is there a browser equivalent to https or an alternative method to sending the certificate to the back end? I saw a suggestion to proxy API requests and add the certificate that way, but I am unsure if that's the way to proceed.

Thanks so much!!

httpsAgent.js

const https = require('https');

const createAgent = (data) => {
  const httpsAgent = new https.Agent({
    ca: data,
    rejectUnauthorized: true,
    checkServerIdentity() {
      return undefined;
    },
  });
  return httpsAgent;
};

index.js

axios
  .get('/certificate.pem')
  .then(({ data }) => {
    httpsAgent = createAgent(data);
  })
  .catch((err) => {
    console.log(err);
  })
  .finally(() => {
    axios.interceptors.request.use((config) => {
      const newConfig = {
        ...config,
        httpsAgent,
      };
      return newConfig;
    });
  });
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda