DEV Community

Discussion on: React & Firebase: Add Firebase to a React App

Collapse
adityamitra profile image
Aditya Mitra

I really like firebase. It would be great if they would allow us to perform cross-origin API requests in firebase functions.

Collapse
farazamiruddin profile image
faraz ahmad Author

I like it too! You can do cross-origin requests. You just need to use the cors npm package.

Here's an example I pulled from a function I wrote.

import * as functions from "firebase-functions";
import * as Cors from "cors";

const cors = Cors({ origin: true });

export const handleCrossOriginRequest = functions.https.onRequest((req, res) => {
  cors(req, res, async () => {
    // your logic here
  });
});

Hope this helps!

Collapse
adityamitra profile image
Aditya Mitra • Edited on

Yeah, but you need to set the billing method first.
That's painful.

Thread Thread
farazamiruddin profile image
faraz ahmad Author

I see. What do you need cross-origin requests for if I may ask?