Ive followed instructions at https://cloud.google.com/functions/docs/writing/http#functions_http_cors-python
So my code has this at the end
# 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': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600'
}
return ('', 204, headers)
# Set CORS headers for the main request
headers = {
'Content-Type':'application/json',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
}
# END CORS
return (res, 200, headers)
where res is JSON
from a simple node app, im calling via
this.http.post(payloadTarget.url, JSON.stringify(clone)).subscribe(res => {
console.log('request complete', res);
},
err => {
console.log('request failed', err);
});
im getting this error on console
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
when testing a POST or OPTIONS using Postman i dont see the error but i also dont see the HEADERS im supposed to
im sure its something simple but looking at others similar questions and answers cant find anything that points to my issue
OPTIONSrequest withcurl?curl -i -X OPTIONS <your function URL>- Dustin Ingramgcloud functions deploy functionName --runtime python37 --trigger-httpand the curl returnsHTTP/2 200 content-type: text/html; charset=utf-8 function-execution-id: ms2z3dcwv1tz x-cloud-trace-context: d4b120a314d0d4a2bb8b7f57d0f5baa7;o=1 date: Thu, 01 Nov 2018 07:47:38 GMT server: Google Frontend content-length: 2 alt-svc: quic=":443"; ma=2592000; v="44,43,39,35"- Tariqcurl -i -X OPTIONS <your function URL>and I getaccess-control-allow-headers: Content-Type access-control-allow-methods: POST, OPTIONS access-control-allow-origin: * access-control-max-age: 3600 content-type: text/html; charset=utf-8Just doesn't work with Chrome. - Watson