1
0
mirror of https://gitlab.com/MoonTestUse1/AdministrationItDepartmens.git synced 2025-08-14 00:25:46 +02:00

Создание чата

This commit is contained in:
MoonTestUse1
2025-01-05 05:43:45 +06:00
parent 357acd11a1
commit ba0b0ec72b
16 changed files with 1619 additions and 29 deletions

View File

@@ -1,40 +1,38 @@
"""Main application module"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from . import models
from .routers import admin, employees, requests, auth, statistics
from app.api.api import api_router
from app.core.config import settings
from app.core.scheduler import setup_scheduler
from app.websockets.chat import handle_chat_connection
app = FastAPI(
# Включаем автоматическое перенаправление со слэшем
redirect_slashes=True,
# Добавляем описание API
title="Support System API",
description="API для системы поддержки",
version="1.0.0"
title=settings.project_name,
openapi_url=f"{settings.api_v1_str}/openapi.json"
)
# CORS configuration
origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://127.0.0.1:8080",
"http://185.139.70.62", # Добавляем ваш production домен
]
# Настройка CORS
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
expose_headers=["*"]
)
# Include routers
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])
app.include_router(employees.router, prefix="/api/employees", tags=["employees"])
app.include_router(requests.router, prefix="/api/requests", tags=["requests"])
app.include_router(admin.router, prefix="/api/admin", tags=["admin"])
app.include_router(statistics.router, prefix="/api/statistics", tags=["statistics"])
# Подключаем роутеры
app.include_router(api_router, prefix=settings.api_v1_str)
# WebSocket для чата
app.add_api_websocket_route("/ws/chat", handle_chat_connection)
@app.on_event("startup")
async def startup_event():
"""Действия при запуске приложения"""
setup_scheduler()
@app.on_event("shutdown")
async def shutdown_event():
"""Действия при остановке приложения"""
from app.core.scheduler import scheduler
scheduler.shutdown()