forked from jackey8616/PyFun-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
39 lines (28 loc) · 803 Bytes
/
app.py
File metadata and controls
39 lines (28 loc) · 803 Bytes
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
import os
import click
from sanic import Sanic
from sanic.response import json
from sanic_cors import CORS
from stage import add_route as stage_add_route
app = None
def path_check():
path = os.path.join(os.getcwd(), 'tmp/')
if not os.path.exists(path):
os.mkdir(path)
@click.command()
@click.option('--host', default='0.0.0.0', type=str)
@click.option('--port', default=8000, type=int)
@click.option('--test', default=False, type=bool)
def run(host, port, test):
path_check()
global app
app = Sanic()
CORS(app)
app.add_route(index, '/', methods=['GET'])
stage_add_route(app)
if not test:
app.run(host=host, port=port)
async def index(request):
return json({'success': True, 'data': 'Hello World!'})
if __name__ == '__main__':
run()