feat: 优化 getToken 函数,移除无用的响应参数,调整授权过滤逻辑以支持新路径

This commit is contained in:
2025-12-23 13:15:16 +08:00
parent 4bdebd66d4
commit 371d66b289
3 changed files with 8 additions and 13 deletions

View File

@@ -34,7 +34,7 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) =
return false;
}
// 放开首页
if (pathname.startsWith('/root/home')) {
if (pathname.startsWith('/root/home') || pathname === '/root/cli') {
return false;
}
// 放开api 以 /api /v1, /client, /serve 开头的请求
@@ -47,8 +47,11 @@ const authFilter = async (req: http.IncomingMessage, res: http.ServerResponse) =
if (share === 'public') {
return false;
}
const { token } = await getToken(req, res)
const { token } = await getToken(req)
if (!token) {
// no token 转到登录页面
res.writeHead(302, { Location: `/root/home/` });
res.end();
return false;
}
const tokenUser = await getTokenUserCache(token);