-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
39 lines (27 loc) · 1 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, send_from_directory
from sonora.wsgi import grpcWSGI
import helloworld_pb2
import helloworld_pb2_grpc
FORMAT_STRING = "Hello, {request.name}"
app = Flask(__name__)
class Greeter(helloworld_pb2_grpc.GreeterServicer):
def SayHello(self, request, context):
print(f"We are saying hello to {request.name}")
return helloworld_pb2.HelloReply(message=FORMAT_STRING.format(request=request))
def SayRepeatHello(self, request, context):
return helloworld_pb2.HelloReply(
message=FORMAT_STRING.format(request=request) * request.count
)
@app.route("/")
def index():
return send_from_directory(".", "index.html")
@app.route("/<path:path>")
def foo(path):
if path == "/":
path = "index.html"
# This appears to filter ../ for us.
return send_from_directory(".", path)
if __name__ == "__main__":
app.wsgi_app = grpcWSGI(app.wsgi_app)
helloworld_pb2_grpc.add_GreeterServicer_to_server(Greeter(), app.wsgi_app)
app.run()