Skip to content

Commit 602eb0c

Browse files
authored
Add files via upload
0 parents  commit 602eb0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1545
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# FastAPI Template
2+
3+
### app - Backend FastAPI
4+
5+
# Настройка
6+
7+
### Настройка происходит в файле .env его нет в репозитории, т.к. он конфиденциален, но я предоставил файл .env-dist создайте на его основе файл .env и проведите все необходимые настройки.
8+
9+
# Установка зависимостей
10+
11+
### В основе проекта лежит пакетный менеджер poetry, но я так же предоставил файл зависимостей requirements.txt, что бы вы могли установить зависимости через пакетный менеджер pip.
12+
13+
`poetry install` - Вариант с использованием poetry.
14+
15+
`pip install -r requirements.txt` - Вариант с использованием pip.
16+
17+
# Запуск
18+
19+
### Для запуска воспользуйтесь ниже приведёнными командами.
20+
21+
`python -m app` - Команда для запуска backend'а.

alembic.ini

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
[alembic]
2+
script_location = migrations
3+
prepend_sys_path = . app
4+
version_path_separator = os
5+
sqlalchemy.url = driver://user:pass@localhost/dbname
6+
7+
[loggers]
8+
keys = root,sqlalchemy,alembic
9+
10+
[handlers]
11+
keys = console
12+
13+
[formatters]
14+
keys = generic
15+
16+
[logger_root]
17+
level = WARN
18+
handlers = console
19+
qualname =
20+
21+
[logger_sqlalchemy]
22+
level = WARN
23+
handlers =
24+
qualname = sqlalchemy.engine
25+
26+
[logger_alembic]
27+
level = INFO
28+
handlers =
29+
qualname = alembic
30+
31+
[handler_console]
32+
class = StreamHandler
33+
args = (sys.stderr,)
34+
level = NOTSET
35+
formatter = generic
36+
37+
[formatter_generic]
38+
format = %(levelname)-5.5s [%(name)s] %(message)s
39+
datefmt = %H:%M:%S

app/__main__.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import uvicorn
2+
from fastapi import FastAPI, Request
3+
from fastapi.middleware.cors import CORSMiddleware
4+
from sqlalchemy.ext.asyncio import AsyncSession
5+
6+
from app.api.api_v1 import api
7+
from app.core.config import settings
8+
from app.database import Database
9+
from app.database.database import engine
10+
11+
app = FastAPI(openapi_url=f"{settings.API_V1_STR}/openapi.json")
12+
13+
14+
@app.middleware("http")
15+
async def session_db(request: Request, call_next):
16+
async with AsyncSession(bind=engine, expire_on_commit=False) as session:
17+
request.state.db = Database(session)
18+
response = await call_next(request)
19+
return response
20+
21+
22+
app.add_middleware(
23+
CORSMiddleware,
24+
allow_credentials=True,
25+
allow_origins=[settings.APP_HOST],
26+
allow_methods=["*"],
27+
allow_headers=["*"],
28+
)
29+
30+
app.include_router(api.api_router, prefix=settings.API_V1_STR)
31+
32+
if __name__ == "__main__":
33+
uvicorn.run(app, host=settings.APP_HOST, port=settings.APP_PORT)
2.07 KB
Binary file not shown.

app/api/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
API Проекта
3+
"""
202 Bytes
Binary file not shown.
2.83 KB
Binary file not shown.

app/api/api_v1/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""
2+
Первая версия API
3+
"""
220 Bytes
Binary file not shown.
564 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)