feat: 接口统一优化

This commit is contained in:
2026-05-23 13:45:58 +08:00
parent a3b1fba3ea
commit 7d68db723b
20 changed files with 302 additions and 302 deletions
+4 -5
View File
@@ -23,18 +23,18 @@ export const publicApiRoutes: ApiRouteRule[] = [
];
/** 路径匹配:支持精确匹配、`/**` 前缀通配和 RegExp */
function matchPath(rulePath: string | RegExp, pathname: string): boolean {
const matchPath = (rulePath: string | RegExp, pathname: string): boolean => {
if (rulePath instanceof RegExp) return rulePath.test(pathname);
if (rulePath.endsWith("/**")) {
const prefix = rulePath.slice(0, -3);
return pathname === prefix || pathname.startsWith(`${prefix}/`);
}
return pathname === rulePath;
}
};
/** 判断当前请求是否命中公开路由规则 */
export function isPublicApiRoute(pathname: string, method: string): boolean {
return publicApiRoutes.some((rule) => {
export const isPublicApiRoute = (pathname: string, method: string): boolean =>
publicApiRoutes.some((rule) => {
const methods = Array.isArray(rule.method)
? rule.method
: rule.method
@@ -43,4 +43,3 @@ export function isPublicApiRoute(pathname: string, method: string): boolean {
const methodMatched = !methods || methods.includes(method as HttpMethod);
return methodMatched && matchPath(rule.path, pathname);
});
}