项目基础模块代码
This commit is contained in:
@ -4,6 +4,11 @@ from fastapi.middleware.cors import CORSMiddleware
|
||||
from app.application.token_middleware import TokenMiddleware
|
||||
from app.application.logger_middleware import LoggerMiddleware
|
||||
|
||||
from app.api.common.upload_file import upload_files
|
||||
from app.api.sys.login_api import login
|
||||
from app.api.sys.sys_user_api import user
|
||||
from app.api.business.project_api import project
|
||||
|
||||
my_app = FastAPI()
|
||||
|
||||
|
||||
@ -18,6 +23,14 @@ my_app.add_middleware(
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
#注意中间的顺序,这个地方是倒序执行的
|
||||
'''
|
||||
注意中间的顺序,这个地方是倒序执行的
|
||||
'''
|
||||
my_app.add_middleware(LoggerMiddleware)
|
||||
my_app.add_middleware(TokenMiddleware)
|
||||
|
||||
my_app.include_router(user, prefix="/user", tags=["用户管理API"])
|
||||
my_app.include_router(login, prefix="/login", tags=["用户登录接口"])
|
||||
my_app.include_router(upload_files, prefix="/upload", tags=["文件上传API"])
|
||||
my_app.include_router(project, prefix="/proj", tags=["项目管理API"])
|
||||
|
||||
|
10
app/application/exception_handler.py
Normal file
10
app/application/exception_handler.py
Normal file
@ -0,0 +1,10 @@
|
||||
from fastapi import HTTPException, Request
|
||||
from app.common.reponse_code import response_error
|
||||
|
||||
from app import my_app
|
||||
"""全局异常处理"""
|
||||
|
||||
|
||||
@my_app.exception_handlers(HTTPException)
|
||||
async def http_exception(request: Request, he: HTTPException):
|
||||
return response_error(request.url + "出现异常:" + he.detail)
|
@ -2,8 +2,8 @@ from fastapi import status
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
from urllib.request import Request
|
||||
from jwt import PyJWTError
|
||||
from common import reponse_code as rc
|
||||
from common import jwt_check as jc
|
||||
from app.common import reponse_code as rc
|
||||
from app.common import jwt_check as jc
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user