【发布时间】:2020-08-04 10:08:39
【问题描述】:
我有一个反应微服务(通过 nginx)部署到谷歌云运行,其后端的环境变量设置为另一个运行 gunicorn 的谷歌云运行实例,该实例为后端提供服务。
我的 Flask 应用程序是按照我能找到的关于允许 CORS 的所有内容设置的:
app = Flask(__name__)
app.config.from_object(config)
CORS(app, resources={r"/*": {"origins": "*"}})
app.config['CORS_HEADERS'] = 'Content-Type'
return app
# Different file, a blueprint's urls:
@blueprint.route('/resources')
@cross_origin()
def get_resources():
...
但我仍然感到害怕Access to XMLHttpRequest at 'https://backend/resources/' from origin 'https://frontend' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
有没有人对此有任何见解/知道在哪里可以解决这个问题?我想用我的微服务设置 GKE,但最初选择了阻力最小的路径,以便在云中建立 POC。我让后端与我的 Cloud SQL 实例对话,我非常接近!
谢谢
【问题讨论】:
-
您能否提供一个最小的 Dockerfile / app.py 以在部署到 Cloud Run 时重现此问题?
-
是的,当我有更多时间时,我可以尝试,希望今晚。有趣的一件事是,如果我 curl -I 使用我的资源 (backend/resources) 的后端,我确实在标头中看到了允许 cors,但我从服务器获得了 404 作为响应?
-
404 是我的错。现在似乎 Cloud Run 正在对同一端点(http s://backend/resources -> http://backend/resources)进行永久重定向(308)
标签: flask google-cloud-platform cors google-cloud-run flask-cors