-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (50 loc) · 1.53 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from mangum import Mangum
from config.db import init_db
from models.tags_models import Tag
from routes.admin_routes import admin_router
from routes.plant_routes import plant_router
from routes.token_router import token_router
from routes.user_routes import user_router
client = {}
@asynccontextmanager
async def lifespan(app: FastAPI):
client["connection"] = await init_db()
yield
client.clear()
app = FastAPI(lifespan=lifespan)
handler = Mangum(app)
def configure():
configure_routes()
configure_app()
def configure_routes():
@app.get("/api", tags=["root"])
def root():
return "Welcome to PlantUrbanus"
app.include_router(admin_router, prefix="/api/admin", tags=[Tag.admin])
app.include_router(user_router, prefix="/api/users", tags=[Tag.users])
app.include_router(plant_router, prefix="/api/plants", tags=[Tag.plants])
# app.include_router(aroid_router, prefix="/aroids", tags=[Tag.aroids])
app.include_router(token_router, tags=["token"])
def configure_app():
origins = [
"http://localhost:3000",
"http://localhost:8000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
def main():
configure()
uvicorn.run(reload=True, app="main:app")
if __name__ == "__main__":
main()
else:
configure()