Google app engine 配置Google App Engine以服务于JS客户端应用程序
我有一个基本的Google app engine 配置Google App Engine以服务于JS客户端应用程序,google-app-engine,flask,google-cloud-platform,Google App Engine,Flask,Google Cloud Platform,我有一个基本的flask应用程序,它使用flask\u restful扩展(用于提供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 Hello
flask
应用程序,它使用flask\u restful
扩展(用于提供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将从
模板/index.html
目录
但是,当访问/
路由时,我不想呈现模板。相反,我希望在app engine项目中的一个完全不同的目录中提供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
但这是行不通的。那么,我如何在GAE中为使用flask rest API的JS客户机提供服务呢?在App Engine的生产环境中不建议这样做,您可以决定是使用Python flask还是JS(React、Angular、Vue)开发整个应用程序
最好的解决方案是将应用程序划分为在GAE上运行这是否意味着一个服务是纯Python/Flask Rest API,另一个服务是JS客户端?如果是这样,我假设dispatch.yaml会将所有流量定向到“JS客户端”服务,然后该服务使用restful api服务?是和是。一个服务将使用Python,另一个使用JavaScript,一旦向/index(例如)发出请求,您的[dispatch.yaml][1]将把流量定向到JS服务。[1];
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