I have rerouted an external API call using Firebase Functions and everything seems to be working just fine (I have the paid plan) however, I am not sure how to pass parameters from the client side. The code on the server side looks like this:
const functions = require("firebase-functions");
const cors = require("cors")({ origin: true });
const { default: axios } = require("axios");
exports.news = functions.https.onRequest((request, response) => {
cors(request, response, () => {
var config = {
headers: {
"X-Api-Key": functions.config().news.key,
},
};
axios
.get(
"https://newsapi.org/v2/everything?q=usa&from=2021-08-27&to=2021-08-28&sortBy=popularity",
config
)
.then((res) => {
response.send(res.data);
})
.catch((error) => {
response.sendStatus(error);
});
});
});
What I will be passing from the client side is the from and to dates which currently are hard coded in the url. Just to make sure, am I doing it right to make an API call from the client side using the generated link from the Firebase Functions:
https://us-central1-<PROJECT-NAME>.cloudfunctions.net/news/?
Thanks in advance for all your replies.