There is no APP
in cloud functions. You can set the CORS headers as stated in google cloud documentations and return your JSON as how you write in Flask.
The example below function called hello_world
which is used for a post request. It return the status and headers of the CORS
.
from flask import jsonify
def hello_world(request):
request_json = request.get_json()
# Set CORS headers for the preflight request
if request.method == 'OPTIONS':
# Allows GET requests from any origin with the Content-Type
# header and caches preflight response for an 3600s
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600'
}
return ('', 204, headers)
# Set CORS headers for the main request
headers = {
'Access-Control-Allow-Methods': 'POST',
'Access-Control-Allow-Origin': '*'
}
if request_json and 'labels' in request_json:
# THIS IS THE PLACE YOU WRITE YOUR CODE.
# AWLAYS RETURN WITH THE HEADERS AND STATUS
return (jsonify({"ok": "Great Day 2"}), 200, headers)
def predict(request): cors_enabled_function(request) # do the rest of my function
– Unthankful