monitoring/app.py

44 lines
1.4 KiB
Python

# _*_ coding: utf-8 _*_
# @Time :2022/5/26 09:23
# @Email :508737091@qq.com
# @Author :qiangyanwen
# @File :app.py
from fastapi import FastAPI
from config.log import logger
from router import routers
from config import settings
from utils.system import host
from fastapi.middleware.cors import CORSMiddleware
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"]