I am making an http request from an angular form like that:
this.http.post(this.endPoint, formData, { responseType: 'text' }).subscribe(
res => {
console.log(res);
}
)
And I have a simple cloud function:
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
exports.test = functions.https.onRequest((req, res) => {
cors(req, res, () => {
const data = req.body;
res.send(`Hello from Firebase! ${data}`);
});
})
However the req.body does not work and i get this response :
Hello from Firebase! [object Object]
Is there any idea why this happens?
If you're trying to print the req.body
value, you first have to convert it from a JavaScript object to a string:
res.send(`Hello from Firebase! ${JSON.stringify(data)}`);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With