-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
47 lines (34 loc) · 969 Bytes
/
main.py
File metadata and controls
47 lines (34 loc) · 969 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
40
41
42
43
44
45
46
47
import uvicorn
from fastapi import FastAPI
from fastapi.templating import Jinja2Templates
from starlette.requests import Request
from database.db import SessionLocal
from router import router
app = FastAPI()
app.include_router(router)
templates = Jinja2Templates(directory="templates")
@app.middleware("http")
async def db_session_middleware(request: Request, call_next):
try:
request.state.db = SessionLocal()
response = await call_next(request)
finally:
request.state.db.close()
return response
@app.get("/")
def index(request: Request):
return templates.TemplateResponse("index.html", {
"request": request
})
@app.get("/version")
async def get_version():
"""
Обработка запроса на версию приложения.
:return:
"""
return "Version"
def __main():
port = 8000
uvicorn.run(app, host="0.0.0.0", port=port)
if __name__ == "__main__":
__main()