-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
35 lines (26 loc) · 801 Bytes
/
app.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
"""Main application runner."""
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from complainer.db import database
from complainer.resources.routes import api_router
origins = ['http://localhost', 'http://localhost:8000']
app = FastAPI()
app.include_router(api_router)
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
@app.on_event('startup')
async def startup() -> None:
"""Start web app. Connect to DB."""
await database.connect()
@app.on_event('shutdown')
async def shutdown() -> None:
"""Start web app. Disconnect from DB."""
await database.disconnect()
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=8000)