I just finished the Hello World Google Cloud Functions tutorial and received the following response headers:
Connection → keep-alive Content-Length → 14 Content-Type → text/plain; charset=utf-8 Date → Mon, 29 Feb 2016 07:02:37 GMT Execution-Id → XbT-WC9lXKL-0 Server → nginx
How can I add the CORS headers to be able to call my function from my website?
You set a CORS configuration on a bucket by specifying information, such as HTTP methods and originating domains, that identify the types of requests the bucket can accept. You cannot manage CORS using the console. Use gsutil instead. Create a JSON file with the CORS configuration you would like to apply.
exampleFunction = functions. https. onRequest((request, response) => { cors(request, response, () => {}); return response. send("Hello from Firebase!"); });
I recently found that Google Drive does accept CORS requests if a valid access token is provided.
here we go:
exports.helloWorld = function helloWorld(req, res) { res.set('Access-Control-Allow-Origin', "*") res.set('Access-Control-Allow-Methods', 'GET, POST'); if (req.method === "OPTIONS") { // stop preflight requests here res.status(204).send(''); return; } // handle full requests res.status(200).send('weeee!); };
then you can jquery/whatever it as usual:
$.get(myUrl, (r) => console.log(r))
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