这是我的主页功能:
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
这是我得到的错误:
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.
如果可以帮助我更多,请访问以下网站:http://fortest099.appspot.com/
答案 0 :(得分:1)
在App Engine响应上启用CORS的正确方法是在app.yaml中的“ handlers”元素下定义标头。请参见docs示例:
handlers:
- url: /images
static_dir: static/images
http_headers:
Access-Control-Allow-Origin: http://mygame.appspot.com
如果您要从Cloud Storage XML API检索图像,则必须enable CORS at the bucket level。