I am using cloud functions for firebase and trying to build a kind of REST API.
What I want is to allow only one origin to make the request to my REST API. For example, I don't want to be allowed to request my API from postman or something like that but only from mywebsite.com.
So Cloud Functions for Firebase is a node js env so this is my current situation :
const cors = require('cors')({origin: "http://mywebsite.com"});
exports.addMessage = functions.https.onRequest((req, res) => {
const textMessage = req.query.text;
cors(req,res,()=>{
firebase.database().ref('/messages').push({original: original}).then(snapshot => {
res.status(200).send(textMessage)
//this send result to every origin that requested whereas I want to allow only mywebsite.com
});
})
});
Any solution ?
Thanks