50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
import os
|
|
|
|
from uvicorn.middleware.proxy_headers import ProxyHeadersMiddleware
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from fastapi.staticfiles import StaticFiles
|
|
from datetime import datetime, timezone
|
|
|
|
from .conf import get_settings
|
|
from .routes import api_route
|
|
|
|
settings = get_settings()
|
|
|
|
VERSION = "1.0.0"
|
|
UP_TIME = datetime.now(timezone.utc)
|
|
|
|
app = FastAPI(
|
|
title="Fast API",
|
|
version=VERSION,
|
|
root_path=settings.ROOT_PATH,
|
|
)
|
|
|
|
@app.get(
|
|
"/healthcheck",
|
|
status_code=200
|
|
)
|
|
async def healthcheck():
|
|
return {
|
|
"uptime": UP_TIME,
|
|
"version": VERSION
|
|
}
|
|
|
|
app.add_middleware(ProxyHeadersMiddleware, trusted_hosts=["*"])
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
#Создание каталога для web приложения
|
|
os.makedirs(os.path.join('web'), exist_ok=True)
|
|
|
|
#Подключаем все ендпоинты и роуты до маунта статических файлов
|
|
app.include_router(api_route)
|
|
|
|
#Подключение собранного web приложения
|
|
app.mount("/", StaticFiles(directory="web", html=True), name="web") |