添加初始化代码
This commit is contained in:
parent
91c977fc16
commit
7de25d3f90
45
app.py
45
app.py
|
|
@ -4,11 +4,46 @@
|
||||||
# @Author :qiangyanwen
|
# @Author :qiangyanwen
|
||||||
# @File :app.py
|
# @File :app.py
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from config.log import logger
|
||||||
|
|
||||||
from router import routers
|
from router import routers
|
||||||
from fastapi import status
|
|
||||||
from fastapi.responses import JSONResponse
|
from config import settings
|
||||||
from fastapi.encoders import jsonable_encoder
|
from utils.system import host
|
||||||
import uvicorn
|
from fastapi.middleware.cors import CORSMiddleware
|
||||||
from config import Debug
|
|
||||||
|
def create_app() -> FastAPI:
|
||||||
|
logger.info("loading application configuration")
|
||||||
|
|
||||||
|
logger.info("create FastApi app object")
|
||||||
|
|
||||||
|
app = FastAPI(
|
||||||
|
debug=settings.PROJECT.DEBUG,
|
||||||
|
title=settings.SWAGGER.TITLE,
|
||||||
|
description=settings.SWAGGER.DESCRIPTION,
|
||||||
|
version="v1"
|
||||||
|
)
|
||||||
|
for router in routers:
|
||||||
|
app.include_router(router)
|
||||||
|
logger.info("Adding a New route success")
|
||||||
|
logger.info("Start registering middleware")
|
||||||
|
app.add_middleware(
|
||||||
|
CORSMiddleware,
|
||||||
|
|
||||||
|
allow_origins=["*"],
|
||||||
|
allow_credentials=True,
|
||||||
|
allow_methods=["*"],
|
||||||
|
allow_headers=["*"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if settings.PROJECT.DEBUG:
|
||||||
|
logger.info("Application started successfully:{}".format(CORSMiddleware.__name__))
|
||||||
|
logger.info(f"Server address http://{host}:{settings.PROJECT.PORT}")
|
||||||
|
logger.info(f"Api doc address http://{host}:{settings.PROJECT.PORT}{settings.SWAGGER.DOCS_URL}")
|
||||||
|
logger.info(f"Api redoc address http://{host}:{settings.PROJECT.PORT}{settings.SWAGGER.REDOC_URL}")
|
||||||
|
return app
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ["create_app"]
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue