-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
30 lines (23 loc) · 849 Bytes
/
main.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
import uvicorn
from starlette.applications import Starlette
from starlette.middleware import Middleware
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.middleware.cors import CORSMiddleware
from config import settings
from config.db import engine, Base
from src.middleware import JwtWebSocketsAuthMiddleware
from src.routes import routes
app = Starlette(
debug=settings.DEBUG,
routes=routes,
middleware=[
Middleware(AuthenticationMiddleware, backend=JwtWebSocketsAuthMiddleware()),
Middleware(CORSMiddleware, allow_origins=settings.CORS_ALLOWED_HOSTS)
]
)
@app.on_event("startup")
async def startup():
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
if __name__ == "__main__":
uvicorn.run(app, host='0.0.0.0', port=8000)