-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·75 lines (63 loc) · 2.09 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import asyncio
import uvicorn
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.utils import get_openapi
from fastapi.security import OAuth2PasswordBearer
from api.account.router import router as router_account
from api.attachment.router import router as router_attachment
from api.group.router import router as router_group
from src.db import create_tables, async_session_maker
logging.basicConfig(level=logging.WARNING)
logging.getLogger('sqlalchemy.engine').setLevel(logging.WARNING)
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
api = FastAPI(
title='API By Reques6e',
version='0.1.0',
redoc_url=None,
openapi_tags=[
{
"name": "Account",
"description": "Эндпоинты для работы с учетной записью пользователя."
}
],
)
origins = [
# 3000 - порт, на котором работает фронтенд на React.js
"http://localhost:3000",
]
api.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["GET", "POST", "OPTIONS", "DELETE", "PATCH", "PUT"],
allow_headers=["Content-Type", "Set-Cookie", "Access-Control-Allow-Headers",
"Access-Control-Allow-Origin",
"Authorization"],
)
api.include_router(router_account)
api.include_router(router_attachment)
api.include_router(router_group)
api.openapi_schema = get_openapi(
title="API By Reques6e",
version="0.1.0",
description="API для работы с учетными записями пользователей",
routes=api.routes,
)
api.openapi_schema["components"]["securitySchemes"] = {
"BearerAuth": {
"type": "http",
"scheme": "bearer",
"bearerFormat": "JWT"
}
}
api.openapi_schema["security"] = [{"BearerAuth": []}]
if __name__ == '__main__':
asyncio.run(create_tables())
uvicorn.run(
app='app:api',
host='0.0.0.0',
port=91,
reload=True # В проде офнуть нужно
)