-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
46 lines (34 loc) · 837 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
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from contextlib import asynccontextmanager
from routers import system, doc, lookup
from loguru import logger
from routers import lookup
# load env
load_dotenv()
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info('Startup!')
yield
logger.info('Closed!')
# create app
app = FastAPI(lifespan=lifespan)
# 允许的访问域
origins = ["*"]
# 中间件
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Ping for test
@app.get("/")
async def read_root():
return {"Hello": "World"}
# Routers
app.include_router(system.router)
app.include_router(doc.router)
app.include_router(lookup.router)