Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable CORS with Cloud Endpoints?

Is there a slick way to enable CORS with the Cloud Endpoints?

(Adding "Access-Control-Allow-Origin: *" or something like this to the response)

Thanks, Brandon

like image 254
Brandon Avatar asked Jul 30 '12 02:07

Brandon


People also ask

What is a CORS enabled endpoint?

CORS (Cross-origin resource sharing) is a standard mechanism that allows XMLHttpRequest (XHR) calls executed in a web page to interact with resources from different origins. Without CORS, the same-origin policy enforced by all browsers would prevent cross-origin requests.

How do I enable CORS policy in AWS API gateway?

To support CORS, therefore, a REST API resource needs to implement an OPTIONS method that can respond to the OPTIONS preflight request with at least the following response headers mandated by the Fetch standard: Access-Control-Allow-Methods. Access-Control-Allow-Headers. Access-Control-Allow-Origin.

How do I fix the CORS issue in API gateway?

Cross-Origin Resource Sharing (CORS) errors occur when a server doesn't return the HTTP headers required by the CORS standard. To resolve a CORS error from an API Gateway REST API or HTTP API, you must reconfigure the API to meet the CORS standard.


2 Answers

As CORS works on production for Cloud Endpoints. What I did to test on devserver (local) was to disable the browser security. For Dartium (I think Chrome also) use --disable-web-security parameter on startup.

like image 179
kcaldas Avatar answered Nov 06 '22 14:11

kcaldas


Try adding this to the yaml file of your endpoint:

x-google-endpoints:
  - name: "{your-endpoint-host-name}"
    allowCors: "true"
like image 37
Janos Elohazi Avatar answered Nov 06 '22 14:11

Janos Elohazi