修复接口文档无限重定向问题
This commit is contained in:
parent
a3888ac144
commit
47b98e4043
@ -66,7 +66,7 @@ service.interceptors.response.use(
|
||||
// 这个状态码是和后端约定好的
|
||||
const code = response.data.code || unauthorized_code
|
||||
const message = response.data.message || '后端接口无返回内容'
|
||||
const refresh = response.headers.refresh
|
||||
const refresh = response.headers['if-refresh']
|
||||
|
||||
if (response.config.responseType === 'blob') {
|
||||
// 如果是文件流,直接过
|
||||
|
@ -11,7 +11,7 @@ from fastapi.security import OAuth2PasswordBearer
|
||||
"""
|
||||
系统版本
|
||||
"""
|
||||
VERSION = "1.7.3"
|
||||
VERSION = "1.7.4"
|
||||
|
||||
"""安全警告: 不要在生产中打开调试运行!"""
|
||||
DEBUG = True
|
||||
|
@ -52,9 +52,9 @@ class AuthValidation:
|
||||
# print("当前时间", buffer_time, datetime.fromtimestamp(buffer_time))
|
||||
# print("剩余时间", exp - buffer_time)
|
||||
if buffer_time >= exp:
|
||||
request.scope["refresh"] = 1
|
||||
request.scope["if-refresh"] = 1
|
||||
else:
|
||||
request.scope["refresh"] = 0
|
||||
request.scope["if-refresh"] = 0
|
||||
except jwt.exceptions.InvalidSignatureError:
|
||||
raise CustomException(msg="无效认证,请您重新登录", code=cls.error_code)
|
||||
except jwt.exceptions.ExpiredSignatureError:
|
||||
|
@ -67,10 +67,7 @@ async def put_dict_types(data_id: int, data: schemas.DictType, auth: Auth = Depe
|
||||
@app.get("/dict/types/{data_id}/", summary="获取字典类型详细")
|
||||
async def get_dict_type(data_id: int, auth: Auth = Depends(AllUserAuth())):
|
||||
schema = schemas.DictTypeSimpleOut
|
||||
return SuccessResponse(
|
||||
await crud.DictTypeDal(auth.db).get_data(data_id, None, v_schema=schema),
|
||||
refresh=auth.refresh
|
||||
)
|
||||
return SuccessResponse(await crud.DictTypeDal(auth.db).get_data(data_id, None, v_schema=schema))
|
||||
|
||||
|
||||
###########################################################
|
||||
@ -104,10 +101,7 @@ async def put_dict_details(data_id: int, data: schemas.DictDetails, auth: Auth =
|
||||
@app.get("/dict/details/{data_id}/", summary="获取字典元素详情")
|
||||
async def get_dict_detail(data_id: int, auth: Auth = Depends(AllUserAuth())):
|
||||
schema = schemas.DictDetailsSimpleOut
|
||||
return SuccessResponse(
|
||||
await crud.DictDetailsDal(auth.db).get_data(data_id, None, v_schema=schema),
|
||||
refresh=auth.refresh
|
||||
)
|
||||
return SuccessResponse(await crud.DictDetailsDal(auth.db).get_data(data_id, None, v_schema=schema))
|
||||
|
||||
|
||||
###########################################################
|
||||
|
@ -144,6 +144,6 @@ def register_jwt_refresh_middleware(app: FastAPI):
|
||||
@app.middleware("http")
|
||||
async def jwt_refresh_middleware(request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
refresh = request.scope.get('refresh', 0)
|
||||
response.headers["refresh"] = str(refresh)
|
||||
refresh = request.scope.get('if-refresh', 0)
|
||||
response.headers["if-refresh"] = str(refresh)
|
||||
return response
|
||||
|
@ -53,7 +53,8 @@ def create_app():
|
||||
allow_origins=settings.ALLOW_ORIGINS,
|
||||
allow_credentials=settings.ALLOW_CREDENTIALS,
|
||||
allow_methods=settings.ALLOW_METHODS,
|
||||
allow_headers=settings.ALLOW_HEADERS)
|
||||
allow_headers=settings.ALLOW_HEADERS
|
||||
)
|
||||
# 挂在静态目录
|
||||
if settings.STATIC_ENABLE:
|
||||
app.mount(settings.STATIC_URL, app=StaticFiles(directory=settings.STATIC_ROOT))
|
||||
|
@ -42,7 +42,7 @@ http.interceptors.response.use(
|
||||
// 获取错误信息
|
||||
const msg = res.data.message || errorCode[code] || errorCode['default']
|
||||
// 是否刷新token
|
||||
const refresh = res.header.refresh
|
||||
const refresh = res.header['if-refresh']
|
||||
if (code === 500) {
|
||||
toast(msg)
|
||||
return Promise.reject(new Error(msg))
|
||||
|
Loading…
x
Reference in New Issue
Block a user