2023-02-21 14:21:53 +08:00
|
|
|
import api.v1.api as api_router_v1
|
|
|
|
import uvicorn
|
2023-03-24 15:37:14 +08:00
|
|
|
from api.utils.common_log import myLogger
|
2023-02-21 14:21:53 +08:00
|
|
|
from fastapi import FastAPI
|
2023-03-14 17:33:06 +08:00
|
|
|
from fastapi.middleware.cors import CORSMiddleware
|
2023-03-16 15:16:12 +08:00
|
|
|
from fastapi.staticfiles import StaticFiles
|
2023-03-21 08:40:35 +08:00
|
|
|
from fastapi.openapi.docs import (
|
|
|
|
get_redoc_html,
|
|
|
|
get_swagger_ui_html,
|
|
|
|
get_swagger_ui_oauth2_redirect_html,
|
|
|
|
)
|
2023-02-21 14:21:53 +08:00
|
|
|
|
2023-03-15 17:55:05 +08:00
|
|
|
myLogger.info_logger("Starting server")
|
2023-04-21 10:42:06 +08:00
|
|
|
app = FastAPI(docs_url=/docs, redoc_url=/redoc,openapi_url="/openapi.json")
|
2023-03-21 08:17:18 +08:00
|
|
|
|
|
|
|
def get_app():
|
2023-03-16 10:05:02 +08:00
|
|
|
origins = [
|
|
|
|
"http://localhost",
|
2023-03-21 10:06:56 +08:00
|
|
|
"http://localhost:9090",
|
2023-03-16 10:05:02 +08:00
|
|
|
]
|
2023-03-14 17:33:06 +08:00
|
|
|
|
2023-03-16 10:05:02 +08:00
|
|
|
app.add_middleware(
|
|
|
|
CORSMiddleware,
|
2023-03-21 10:41:34 +08:00
|
|
|
allow_origins=["*"],
|
|
|
|
allow_credentials=False,
|
2023-03-16 10:05:02 +08:00
|
|
|
allow_methods=["*"],
|
|
|
|
allow_headers=["*"],
|
|
|
|
)
|
2023-03-16 15:12:16 +08:00
|
|
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
2023-04-21 10:29:44 +08:00
|
|
|
app.include_router(api_router_v1.get_api())
|
2023-02-21 14:21:53 +08:00
|
|
|
return app
|
|
|
|
|
2023-03-21 08:17:18 +08:00
|
|
|
@app.get("/docs", include_in_schema=False)
|
|
|
|
async def custom_swagger_ui_html():
|
|
|
|
return get_swagger_ui_html(
|
|
|
|
openapi_url=app.openapi_url,
|
|
|
|
title=app.title + " - Swagger UI",
|
|
|
|
oauth2_redirect_url=app.swagger_ui_oauth2_redirect_url,
|
|
|
|
swagger_js_url="/static/swagger-ui/swagger-ui-bundle.js",
|
|
|
|
swagger_css_url="/static/swagger-ui/swagger-ui.css",
|
|
|
|
)
|
|
|
|
|
|
|
|
@app.get(app.swagger_ui_oauth2_redirect_url, include_in_schema=False)
|
|
|
|
async def swagger_ui_redirect():
|
|
|
|
return get_swagger_ui_oauth2_redirect_html()
|
|
|
|
|
|
|
|
@app.get("/redoc", include_in_schema=False)
|
|
|
|
async def redoc_html():
|
|
|
|
return get_redoc_html(
|
|
|
|
openapi_url=app.openapi_url,
|
|
|
|
title=app.title + " - ReDoc",
|
|
|
|
redoc_js_url="/static/redoc/redoc.standalone.js",
|
|
|
|
)
|
|
|
|
|
2023-02-21 14:21:53 +08:00
|
|
|
if __name__ == "__main__":
|
|
|
|
uvicorn.run("main:get_app", host='0.0.0.0', port=5000, reload=True)
|