Darren Zou
Darren Zou

Reputation: 143

adding the self.response.headers['Access-Control-Allow-Origin'] = '*' does not do anything. webapp2

This is my main page function:

class Home(webapp2.RequestHandler):
    def get(self): 
        self.response.headers.add_header('Access-Control-Allow-Origin', '*')
        self.response.headers.add_header('Access-Control-Allow-Headers', 'Authorization')
        self.response.headers.add_header('Access-Control-Allow-Methods', 'POST, GET, PUT, DELETE')
        homepage = the_jinja_env.get_template('/template/mosaic.html')  
        self.response.write(homepage.render({"data":getData()}))

app.yaml

- url: .*
  script: main.app

And this is the error I got:

Access to image at 'https://storage.googleapis.com/mosaictestlayer1/1' from origin 'http://fortest099.appspot.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Here is the website if it helps me out more: http://fortest099.appspot.com/

Upvotes: 0

Views: 128

Answers (1)

Christopher P
Christopher P

Reputation: 1108

The correct way to enable CORS on your App Engine responses is to define the header under a 'handlers' element in your app.yaml. See the docs example:

handlers:
- url: /images
  static_dir: static/images
  http_headers:
    Access-Control-Allow-Origin: http://mygame.appspot.com

If you're retrieving images from the Cloud Storage XML API then you have to enable CORS at the bucket level.

Upvotes: 1

Related Questions