Enabling CORS on Google App Engine Flexible environment for a Django Application

3,527 views
Skip to first unread message

Swapnil Tiwari

unread,
Aug 30, 2017, 12:51:02 PM8/30/17
to Google App Engine
Hi,

I have been trying to enable CORS on my Django application deployed on Google App Engine flexible environment but no luck. Here is my question on stack overflow with a lot more details - https://stackoverflow.com/questions/45934384/enabling-cors-on-google-app-engine-for-a-django-application

I have followed the January 2017 release notes over here - https://cloud.google.com/endpoints/docs/release-notes but no luck so far

Kindly help me

Regards,
Swapnil

George (Cloud Platform Support)

unread,
Aug 30, 2017, 4:58:44 PM8/30/17
to Google App Engine
You may refer to the "CORS Support" subchapter of the "app.yaml Reference" documentation page
Is your allow origin address correct? 

Swapnil Tiwari

unread,
Aug 30, 2017, 11:07:56 PM8/30/17
to Google App Engine

Yes I did try the CORS example given in the link you just shared.

I added a handler to app.yaml like this:

handlers:
- url: /*
 
http_headers:
    Access-Control-Allow-Origin: '*'
 
Then I ran - gcloud app deploy and got an error. I have attached the screenshot of the error
Screen Shot 2017-08-31 at 8.30.57 AM.png
Message has been deleted

Swapnil Tiwari

unread,
Aug 30, 2017, 11:49:03 PM8/30/17
to Google App Engine
Also, the CORS subchapter says - "You can set HTTP headers for responses of your static file or directory handlers. If you need to set HTTP headers in your script handlers, you should instead do that in your app's code."

I don't want CORS to be enabled on static files. I want it on my REST APIs

George (Cloud Platform Support)

unread,
Aug 31, 2017, 9:21:02 AM8/31/17
to Google App Engine
You seem to have used the wildcard "*" between single quotes '*'. The error message complains about this URL, you should look into it. 

Swapnil Tiwari

unread,
Aug 31, 2017, 10:45:54 AM8/31/17
to Google App Engine
Thanks for the reply Geore. Changing the url to a specific URL for example
-url:/api/v1/sign-up
also did not work

On Thursday, August 31, 2017 at 6:51:02 PM UTC+5:30, George (Cloud Platform Support) wrote:
You seem to have used the wildcard "*" between single quotes '*'. The error message complains about this URL, you should look into e

Mike Hardy

unread,
Aug 31, 2017, 12:03:50 PM8/31/17
to Google App Engine
Based on the comments of this post, it looks like `static_dir` is required for using `http_headers`. It could be some outdated/bad documentation causing some confusion.

George (Cloud Platform Support)

unread,
Sep 7, 2017, 4:10:56 PM9/7/17
to Google App Engine
Hi Swapnil, 

Do you need any more help from us on this issue? You seem to have solved it, as one can read in your twin posting in stackoverflow. 
Reply all
Reply to author
Forward
0 new messages