feat: добавлен запуск FastAPI с использованием uvicorn и создание файла настроек
- Добавлена поддержка утилиты uvicorn для запуска приложения FastAPI. - Создан новый модуль `settings.py` в пакете `core`, содержащий настройки базы данных.
This commit is contained in:
parent
a8272f71c2
commit
b541fdf57a
0
lkeep/core/__init__.py
Normal file
0
lkeep/core/__init__.py
Normal file
24
lkeep/core/settings.py
Normal file
24
lkeep/core/settings.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from pydantic import SecretStr
|
||||||
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||||
|
|
||||||
|
|
||||||
|
class DBSettings(BaseSettings):
|
||||||
|
db_name: str
|
||||||
|
db_user: str
|
||||||
|
db_password: SecretStr
|
||||||
|
db_host: str
|
||||||
|
db_port: int
|
||||||
|
db_echo: bool
|
||||||
|
|
||||||
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf8", extra="ignore")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def db_url(self):
|
||||||
|
return f"postgresql+asyncpg://{self.db_user}:{self.db_password.get_secret_value()}@{self.db_host}:{self.db_port}/{self.db_name}"
|
||||||
|
|
||||||
|
|
||||||
|
class Settings(BaseSettings):
|
||||||
|
db_settings: DBSettings = DBSettings()
|
||||||
|
|
||||||
|
|
||||||
|
settings = Settings()
|
@ -1,8 +1,8 @@
|
|||||||
|
import uvicorn
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
def start():
|
||||||
async def index():
|
uvicorn.run(app="lkeep.main:app", reload=True)
|
||||||
return {"status": "It's ALIVE!"}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user