45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
# encoding: utf-8
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
from src.controller import api_router
|
|
from src.config import *
|
|
from src.utils import *
|
|
|
|
|
|
def startApp():
|
|
# 接口文档配置
|
|
app: FastAPI = FastAPI(
|
|
title=settings.PROJECT_NAME,
|
|
version=settings.PROJECT_VERSION,
|
|
description=settings.PROJECT_DESC
|
|
)
|
|
|
|
# 配置路由
|
|
app.include_router(api_router, prefix=settings.API_PREFIX)
|
|
# 配置静态资源目录
|
|
app.mount("/" + settings.STATIC_DIR, StaticFiles(directory=settings.STATIC_DIR), name=settings.STATIC_DIR)
|
|
# 跨域配置
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=settings.CORS_ORIGINS,
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
return app
|
|
|
|
|
|
app = startApp()
|
|
|
|
if __name__ == "__main__":
|
|
import uvicorn
|
|
|
|
uvicorn.run(
|
|
app=settings.APP_NAME,
|
|
host=settings.HOST,
|
|
port=settings.PORT,
|
|
reload=settings.RELOAD
|
|
)
|