javascript - Fetch POST Request doesn't return response sent using res.send('sampletext'); -
i have cloud function triggered using fetch post request client browser, response fetch call doesn't contain response text cloud function(res.send("sampletext"))
cloud function:
const functions = require('firebase-functions'); const cors = require('cors')({ origin: true }) exports.unlock = functions.https.onrequest((req, res) => { cors(req, res, () => { res.send('bsdasda'); }) })
fetch post request on client browser
fetch("https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", { method: "post", mode: "cors" }).then((response) => { console.log(response) });
this fetch response on client browser
response {type: "cors", url: "https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", redirected: false, status: 200, ok: true, …} body : (...) bodyused : false headers : headers {} ok : true redirected : false status : 200 statustext : "" type : "cors" url : "https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock" __proto__ : response
check out:
fetch("https://us-central1-closing-ratio-32360.cloudfunctions.net/unlock", { method: "post", mode: "cors" }) .then((response) => response.text()) .then((text) => { console.log(text) });
Comments
Post a Comment