| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from project.admin import AdminCustom, MessagePairAdmin | |
| from project.bot.auth import authentication_backend_admin | |
| from project.database import engine | |
| def create_app() -> FastAPI: | |
| app = FastAPI() | |
| from project.bot import bot_router | |
| app.include_router(bot_router, tags=['bot']) | |
| from project.ws import ws_router | |
| app.include_router(ws_router, tags=['ws']) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.mount('/static', StaticFiles(directory="static"), name="static") | |
| admin = AdminCustom(app, engine, authentication_backend=authentication_backend_admin) | |
| admin.add_view(MessagePairAdmin) | |
| return app | |