firebase-functions-snippets
firebase-functions-snippets copied to clipboard
Issue with putting cors function into snippet
I'm confused on where do I exactly place the cors function for the test. Should I place it inside of the function and have another request handler. Or should I place on the function call. Is there anyway you can place all the components inside of the functions. I am a beginner to javascript programming.
exports.ShoePostTest = functions.https.onRequest(cors((request,response) => { // check for requst method if(request.method !== "POST"){ response.status(400).send('Please send a POST request'); return; } console.log(request.body.text) response.send(request.body.text) }))
Hi @kswain1, it should be something like this:
const cors = require('cors')({origin: true});
exports.ShoePostTest = functions.https.onRequest((request,response) => {
cors(request, response, () => {
// check for requst method
if(request.method !== "POST"){
response.status(400).send('Please send a POST request');
return;
}
console.log(request.body.text)
response.send(request.body.text)
})
})
Thanks will give that a try.
@kswain1 Great, Let me know if it works.