【发布时间】:2019-12-15 11:31:43
【问题描述】:
为 App Engine 标准 python 3 运行开发服务器未正确路由请求。
dev_appserver.py app.yaml
app.yaml 文件有 3 个处理程序。
runtime: python37
instance_class: F1
inbound_services:
- warmup
handlers:
- url: /api/.*
script: auto
secure: always
- url: /
static_files: public/index.html
upload: public/index.html
secure: always
- url: /
static_dir: public
secure: always
本地对 /api/whatever 的请求都返回 404 错误。 当我将应用部署到 GCP 时,请求成功。
我设置的原因是静态托管 Angular 7 应用程序,同时还托管 Angular 应用程序调用的 API。
由于该问题仅与开发服务器相关,我认为这是一个错误。这里有一个类似的python 2示例:https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/appengine/standard/angular/app.yaml
还有其他人遇到过这种情况吗?任何解决方法?
更新:根据 cmets 的要求,这里是一个示例 main.py 文件。
# [START gae_python37_app]
import logging
from flask import request, url_for
from flask_api import FlaskAPI, status, exceptions
# Create flask app
app = FlaskAPI(__name__)
@app.route("/api/whatever", methods=["GET"])
def doSomething():
response = {"message":"placeholder"}
return response
if __name__ == "__main__":
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app.
app.run(host="127.0.0.1", port=8080, debug=True)
# [END gae_python37_app]
【问题讨论】:
-
您能否通过提供您的 main.py 文件来提供一个最小的可重现示例?请参阅此处了解更多信息。
标签: python python-3.x google-app-engine google-cloud-platform