1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #!/usr/bin/env python
- """
- @Contact : liuyuqi.gov@msn.cn
- @Time : 2024/03/19 16:50:59
- @License : Copyright © 2017-2022 liuyuqi. All Rights Reserved.
- @Desc :
- """
- from app.config import settings
- from app.extensions.hook import (init_banner, init_middlewares, register_db,
- register_exception_handlers, register_routes)
- from fastapi import FastAPI
- from fastapi.routing import APIRoute
- def custom_generate_unique_id(route: APIRoute) -> str:
- return f"{route.tags[0]}-{route.name}"
- def create_app(config_name="dev") -> FastAPI:
- """
- return FastAPI instance
- """
- fastapp = FastAPI(
- title=settings.PROJECT_NAME,
- description=settings.PROJECT_NAME,
- # version= settings.API_VERSION,
- openapi_url=f"{settings.API_V1_STR}/openapi.json",
- docs_url="/docs",
- redoc_url="/redoc",
- generate_unique_id_function=custom_generate_unique_id,
- )
- init_banner()
- init_middlewares(app=fastapp)
- register_db(app=fastapp)
- register_exception_handlers(app=fastapp)
- register_routes(app=fastapp)
- return fastapp
- fastapp = create_app()
|