from fastapi import FastAPI from fastapi.responses import HTMLResponse from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from backend_fastapi.auth import router as auth_router from backend_fastapi.general import router as general_router from backend_fastapi.database import connect, disconnect @asynccontextmanager async def lifespan(app: FastAPI): await connect() yield await disconnect() app = FastAPI(lifespan=lifespan) origins = [ "http://localhost", "http://localhost:8000", "http://localhost:3000", "http://localhost:5173" ] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) @app.get("/") def index(): html_content = "

Hello METANIT.COM!

" return HTMLResponse(content=html_content) @app.get("/cat") async def get_data(): return {"firstname": "Котофей","lastname":"Барсикофф","age":"10"} app.include_router(router=auth_router, prefix="/auth", tags=["Auth"]) app.include_router(router=general_router, prefix="/general", tags=["General"]) if __name__ == "__main__": import uvicorn uvicorn.run(app, host="0.0.0.0", port=8000)