Search code examples
corsgoogle-cloud-rungoogle-api-gateway

Google Api Gateway with Cloud Run CORS


Is there a way to enable Cors in the Google Api gateway config for Cloud Run services?

I enabled Cors in the service themselves, but I always get

Access to XMLHttpRequest at 'xxx' from origin 'http://localhost:4200/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Wondering if the Api Gateway is the problem, because calling the cloud run service directly works fine.


Solution

  • You could overcome the missing functionality

    • by adding a load balancer
    • create a custom header Guide

    You just need to add the "Access-Control-Origin" header:

    Allow all
    

    Access-Control-Origin:'*'

    See steps for API Gateway and Load balancer.