50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
import os
|
|
import tomllib
|
|
from pathlib import Path
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from route import base, holland_crud, init_data_base, groups_crud, organizations_crud, users_crud, question_crud, choice_crud, response_crud, poll_crud
|
|
import uvicorn
|
|
|
|
# Читаем версию из pyproject.toml
|
|
try:
|
|
# Получаем абсолютный путь к pyproject.toml
|
|
pyproject_path = Path(__file__).parent / "pyproject.toml"
|
|
with open(pyproject_path, "rb") as f:
|
|
pyproject = tomllib.load(f)
|
|
VERSION = pyproject["project"]["version"]
|
|
except Exception as e:
|
|
print(f"Warning: Could not read version from pyproject.toml: {e}")
|
|
VERSION = "0.1.0"
|
|
|
|
# Читаем переменные окружения
|
|
APP_PATH = os.getenv("APP_PATH", "/home/user/api-copp")
|
|
|
|
app = FastAPI(title="api", version=VERSION)
|
|
# Разрешаем CORS для фронтенда (dev). При необходимости сузить список origins.
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["http://localhost:3000", "http://127.0.0.1:3000"],
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
app.include_router(base.router)
|
|
app.include_router(init_data_base.router)
|
|
app.include_router(groups_crud.router)
|
|
app.include_router(organizations_crud.router)
|
|
app.include_router(users_crud.router)
|
|
app.include_router(question_crud.router)
|
|
app.include_router(choice_crud.router)
|
|
app.include_router(response_crud.router)
|
|
app.include_router(poll_crud.router)
|
|
app.include_router(holland_crud.router)
|
|
|
|
|
|
|
|
# Доступна переменная APP_PATH для использования в приложении
|
|
print(f"Application path: {APP_PATH}")
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|