-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
48 lines (36 loc) · 958 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from api import user, auth
from database.config import engine, database, Base
app = FastAPI()
app.include_router(auth.router, prefix="/api")
app.include_router(user.router, prefix="/api")
origins = [
"http://localhost:5173",
]
methods = [
"DELETE",
"GET",
"POST",
"PUT",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=methods,
allow_headers=["*"],
)
@app.on_event("startup")
async def startup():
await database.connect()
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
@app.on_event("shutdown")
async def shutdown():
if database.is_connected:
await database.disconnect()
if __name__ == "__main__":
import uvicorn
# Run the FastAPI application using uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)