【发布时间】:2019-06-29 17:18:35
【问题描述】:
我已经编写了一个烧瓶应用程序并将其部署到应用程序引擎,该应用程序引擎将运行一些 python 脚本并在我向 url 发出 POST 请求时返回一些数据,例如:
import logging
import firebase_admin
from firebase_admin import firestore
import flask
app = flask.Flask(__name__)
@app.route('/test', methods=['POST'])
def get_data():
data = flask.request.json
return flask.jsonify({"test":1000);
我正在尝试向客户端上的“https://****.appspot.com/test”发出如下所示的 POST 请求,该客户端是托管在 Firebase 托管上的网络应用程序,但正在获取“访问权限- Control-Allow-Origin 错误。
fetch('https://***.appspot.com/vrp', {
method: 'POST',
data: null
})
.then(response =>
console.log(`response is ` , response.json()))
我看到 here 可以编辑 app.yaml 但我无法弄清楚。我犯错了吗?
我的 app.yaml:
runtime: custom
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
handlers:
- url: /*
static_dir: /
http_headers:
Access-Control-Allow-Origin: "*"
manual_scaling:
instances: 1
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
【问题讨论】:
-
headers配置仅在 standard environmentapp.yamlfile 中受支持,the flexible one 中不支持。我认为您可能需要在您的应用中明确设置 CORS 标头。 -
@DanCornilescu,感谢您的评论。我想我是用flask_cors想出来的。发布了答案。
标签: javascript firebase google-app-engine google-cloud-platform firebase-hosting