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

302
Visualizações
No 'Access-Control-Allow-Origin' - Firebase Function

I created a GET request using firebase functions. I can receive data using Postman, but not from my FE application.

While accessing the endpoints i'm getting this error

from origin 'http://localhost:4200' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

My FE Code,

  pay() {
    this.http.get(this.settings.createPaymentRequest).subscribe(res => {
      console.log(res);
    })
  }

Server Code,

exports.createRequest = functions.https.onRequest((req, res) => {
const cors = require('cors')({
  origin: '*'
});
...
var options = {
    method: 'POST',
    uri: 'https://test.instamojo.com/api/1.1/payment-requests/',
    form: payload,
    headers: insta_headers,
    json: true
  };

  return rp(options)
    .then(function (response) {
      console.log(response);
      if (response.success) {

        db.collection('PAYMENT_REQUESTS').doc(response.payment_request.id).set({
          LONG_URL: response.payment_request.longurl,
          REQUEST_CREATED_AT: response.payment_request.created_at,
          PAYMENT_STATUS: "STARTED"
        }, {
          merge: true
        }).then(function () {
          response.setHeader(headers);
          res.status(200).send({
            STATUS: "SUCCESS",
            RESPONSE: response.payment_request.longurl
          });
        })
          .catch(function (error) {
            res.status(200).send({
              STATUS: "ERROR",
              RESPONSE: error
            });
          });



      } else return res.status(403).send('Forbidden!');

    })
    .catch(function (e) {
      console.log("ERROR" + e);
      res.status(200).send({
        STATUS: "ERROR",
        RESPONSE: e
      });
    });
});

Please guide me how to resolve this issue.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It looks like you create this

const cors = require('cors')({
  origin: '*'
});

but don't inject it anywhere (unless that is part of the ...)

There should be something like this somewhere

app.use(cors())

(or however your framework does it)

Before trying with your browser again, you can check the response headers in postman to see if the cors headers you are looking for are there:

something like this:

Access-Control-Allow-Origin: *
about 4 years ago · Juan Pablo Isaza Relatório
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