This commit is contained in:
s.mostryukov 2024-08-06 10:05:03 +03:00
parent f866f66a77
commit e8e9e52021
5 changed files with 24 additions and 3 deletions

View File

@ -1,8 +1,9 @@
from contextlib import asynccontextmanager
from fastapi.openapi.docs import get_swagger_ui_html
from starlette.staticfiles import StaticFiles
from settings import settings
from settings import settings, BASE_DIR
from models import db_helper
from api import router as api_router
from views import router as web_router
@ -22,13 +23,24 @@ async def lifespan(app: FastAPI):
main_app = FastAPI(
default_response_class=ORJSONResponse,
lifespan=lifespan,
docs_url=None,
)
main_app.include_router(api_router)
main_app.include_router(web_router)
main_app.mount("/static", StaticFiles(directory="views/static"), name="static")
main_app.mount("/static", StaticFiles(directory=BASE_DIR / "views" / "static"), name="static")
@main_app.get("/docs", include_in_schema=False)
async def custom_swagger_ui_html():
return get_swagger_ui_html(
openapi_url=main_app.openapi_url,
title="My API",
oauth2_redirect_url=main_app.swagger_ui_oauth2_redirect_url,
swagger_js_url="/static/swagger/swagger-ui-bundle.js",
swagger_css_url="/static/swagger/swagger-ui.css",
swagger_favicon_url="/static/swagger/favicon.png",
)
if __name__ == "__main__":
uvicorn.run(

View File

@ -7,8 +7,11 @@ from pydantic_settings import (
BaseSettings,
SettingsConfigDict,
)
from pathlib import Path
BASE_DIR = Path(__file__).parent
class RunConfig(BaseModel):
host: str = "0.0.0.0"
port: int = 8000
@ -46,7 +49,7 @@ class DatabaseConfig(BaseModel):
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=(".env-template", ".env"),
env_file=(BASE_DIR / ".env-template", BASE_DIR / ".env"),
case_sensitive=False,
env_nested_delimiter="__",
env_prefix="SIPI_CONFIG__",

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long