#[SOLVED] GCP- CORS STRIKES AGAIN

4 messages · Page 1 of 1 (latest)

halcyon badger
#

AWS and Azure seem to have a quick fix for this with an option to toggle while creating a Function, GCP does not as far as I know. I have spent the last week and a half reading any documentation, every video on youtube and no matter how I configure my function code and requirements, I can't get it to work. I keep getting the Access-Control-Allow-Origin error.

  1. I have utilized:
    res.setHeader('Access-Control-Allow-Origin', '*');
    res.setHeader('Access-Control-Allow-Methods', 'POST, GET, OPTIONS');
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');

  2. I have changed the environment variable to include Access-Control-Allow-Origin', '*'

  3. I even tried adding CORS to my openapi spec

What am I missing? Am I totally off? is there an obvious thing that I'm missing?
Any tip or tool or video or documentation that can lead me in the right direction would be much appreciated, thank you, Happy CORS Hunting!

uncut basalt
#

Have you tried adding the * wild card res.setHeader('Access-Control-Allow-Origin', '*');
*Note that this will allow all origins please read this article for some more details on CORS https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#the_http_response_headers

Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a "preflight" request to the server hosting the cross-origin resource, in ord...

halcyon badger
#

I did, I had a typo in my original post, but I will read this and make sure I did it properly.

halcyon badger
#

Ok don't laugh, maybe laugh just a little. I finally figured it out. I created an api gateway with a GET openapi spec config, but when I couldn't get the cloud function url to work, I ended up changing the GET spec to POST. SOOOO, when I figured out CORS with my cloud function and that URL was working, I never went back and changed my Openapi spec to GET and it kept giving me a CORS origin error. I rewrote my spec to GET and everything works just fine. I hope this makes sense, I feel like I understand it on a much deeper level now and I still have no clue, haha.