-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
45 lines (30 loc) · 947 Bytes
/
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
40
41
42
43
44
45
import asyncio
import aiohttp_debugtoolbar
import uvloop
from aiohttp_swagger import *
from aiohttp import web
from aiohttp_jwt import JWTMiddleware
from main import settings
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
async def init_app(app):
# add routes
from main.routes import setup_routes
setup_routes(app)
if settings.DEBUG:
setup_swagger(app, swagger_url='/docs')
# enable debugtoolbar
aiohttp_debugtoolbar.setup(app)
async def close_app(app):
pass
if __name__ == '__main__':
app = web.Application(
middlewares=[
settings.DB,
JWTMiddleware(settings.SHARED_SECRET_KEY, credentials_required=False)
]
)
app['settings'] = settings
app.on_startup.append(init_app)
app.on_cleanup.append(close_app)
settings.DB.init_app(app, config=settings.DATABASE)
web.run_app(app, host=settings.HOST, port=settings.PORT)