41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.responses import FileResponse
|
|
import os
|
|
|
|
from backend.database import init_db
|
|
from backend.api import router as api_router
|
|
from backend.telegram_bot import start_bot
|
|
|
|
app = FastAPI(title="Schedule Service")
|
|
|
|
# Инициализация БД (асинхронно при старте)
|
|
|
|
# API роуты
|
|
app.include_router(api_router, prefix="/api")
|
|
|
|
# Статические файлы для фронтенда
|
|
frontend_path = os.path.join(os.path.dirname(__file__), "..", "frontend")
|
|
|
|
@app.get("/")
|
|
async def read_root():
|
|
return FileResponse(os.path.join(frontend_path, "public", "index.html"))
|
|
|
|
@app.get("/admin")
|
|
async def read_admin():
|
|
return FileResponse(os.path.join(frontend_path, "admin", "index.html"))
|
|
|
|
# Статические файлы
|
|
app.mount("/static", StaticFiles(directory=os.path.join(frontend_path, "public", "static")), name="static")
|
|
app.mount("/admin/static", StaticFiles(directory=os.path.join(frontend_path, "admin", "static")), name="admin_static")
|
|
|
|
# Запуск Telegram-бота в фоне
|
|
@app.on_event("startup")
|
|
async def startup_event():
|
|
import asyncio
|
|
# Инициализация БД
|
|
await init_db()
|
|
# Запуск бота
|
|
if os.getenv("TELEGRAM_BOT_TOKEN"):
|
|
asyncio.create_task(start_bot())
|
|
|