forked from VinokurovVE/tests
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.0 KiB
43 lines
1.0 KiB
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.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",
|
|
]
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=origins,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
@app.get("/")
|
|
def index():
|
|
html_content = "<h2>Hello METANIT.COM!</h2>"
|
|
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")
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|