【发布时间】:2019-08-23 13:30:04
【问题描述】:
我有一个基本的flask 应用程序,它使用flask_restful 扩展名(用于制作宁静的服务):
main.py
from google.cloud import datastore
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
datastore_client = datastore.Client()
class HelloWorld(Resource):
def get(self):
# retrieve from datastore here
return {'greeting': 'hello'}
api.add_resource(HelloWorld, '/greet')
通常,flask 应用会呈现这样的模板:
@app.route('/')
def home():
return render_template("index.html")
默认情况下,flask 会从
templates/index.html 目录。
但是,当访问 / 路由时,我不想渲染 a 模板。相反,我想在应用引擎项目的一个完全不同的目录中提供一个 JS 客户端应用程序(Angular、React、Vue):
my-gae-project/
app.yaml
main.py
main_test.py
requirements.txt
app/ <--- JS app lives here; consumes flask restful api
src/
index.html
script.js
style.js
build/
index.html
一开始我以为只要修改app.yaml文件指向app/子目录就可以了:
runtime: python37
handlers:
- url: /static
static_dir: static
- url: /app
static_dir: app
- url: /.* <--- route all requests to '/' to app.index.html
script: app/index.html
但这不起作用。那么,我究竟如何在 GAE 中为使用 flask rest API 的 JS 客户端提供服务?
【问题讨论】:
标签: google-app-engine flask google-cloud-platform