Initial commit: Schedule service for son
This commit is contained in:
commit
af2ea7be06
19 changed files with 2270 additions and 0 deletions
41
backend/main.py
Normal file
41
backend/main.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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())
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue