4c88964473
- 新后台 admin-frontend-vue 整工程入库(base=/admin-vue/、History 路由、Nginx 静态托管方案与 verify-dist 校验) - Java AdminConsoleController 改为入口重定向: /admin|/admin.html、/login|/login.html -> /admin-vue/; 删除 classpath:static 旧 admin.html/login.html 单页与 admin.js 副本 - Flask 后台整体退役: 删除 admin_api/auth/main 蓝图、web_source 页面、static 脚本与 admin 相关测试; app.py 收敛为仅注册 version_bp(/api/version、/api/version/latest, 供桌面端更新检查) - AdminApiGuardFilterTest 豁免样例路径 /admin.html -> /admin-vue/
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import axios from 'axios'
|
|
import { isUnauthorized, loginRedirectTarget, shouldRedirectUnauthorized } from './envelope'
|
|
|
|
export { unwrap } from './envelope'
|
|
|
|
export const http = axios.create({
|
|
baseURL: '/',
|
|
withCredentials: true,
|
|
timeout: 30_000,
|
|
})
|
|
|
|
function redirectToLogin(requestUrl?: string): void {
|
|
if (typeof window === 'undefined') return
|
|
// 已在登录页或失败请求即登录端点时不再跳转,避免登录页循环与吞掉登录失败反馈。
|
|
if (!shouldRedirectUnauthorized(window.location.pathname, requestUrl)) return
|
|
const target = loginRedirectTarget(window.location)
|
|
window.location.assign('/admin-vue/login?redirect=' + target)
|
|
}
|
|
|
|
http.interceptors.response.use(
|
|
(response) => {
|
|
// Java 未登录以 HTTP 200 + body.code=401 返回,需统一按未登录处理。
|
|
if (isUnauthorized(response.data)) redirectToLogin(response.config?.url)
|
|
return response
|
|
},
|
|
(error) => {
|
|
if (error?.response?.status === 401 || isUnauthorized(error?.response?.data)) {
|
|
redirectToLogin(error?.config?.url)
|
|
}
|
|
return Promise.reject(error)
|
|
},
|
|
)
|