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?
In the python environment, you can use the flask request object to manage CORS requests.
See the gcloud docs for more.
here we go:
then you can jquery/whatever it as usual:
I've just created webfunc. It's a lightweight HTTP server that supports CORS as well as routing for Google Cloud Functions. Example:
In your project's root, simply add a appconfig.json that looks like this:
Hope this helps.
You can use the CORS express middleware.
package.json
index.js
If you are looking for an actual code sample (and your question is still relevant), I wrote a blog post about that: https://mhaligowski.github.io/blog/2017/03/10/cors-in-cloud-functions.html.
I'm the product manager for Google Cloud Functions. Thanks for your question, this has been a popular request.
We don't have anything to announce just yet, but we're aware of several enhancements that need to be made to the HTTP invocation capabilities of Cloud Functions and we'll be rolling out improvements to this and many other areas in future iterations.
UPDATE:
We've improved the way you deal with HTTP in Cloud Functions. You now have full access to the HTTP Request/Response objects so you can set the appropriate CORS headers and respond to pre-flight OPTIONS requests (https://cloud.google.com/functions/docs/writing/http)