统一API Base URL保存与请求时去除末尾斜杠

This commit is contained in:
mtvpls
2026-07-25 10:57:04 +08:00
parent 19f4957160
commit ca798177b9
16 changed files with 191 additions and 46 deletions
+9 -3
View File
@@ -1,5 +1,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { normalizeApiBaseUrl } from '@/lib/url';
// Token 内存缓存
const tokenCache = new Map<string, { token: string; expiresAt: number }>();
@@ -17,13 +19,16 @@ export interface XiaoyaListResponse {
export class XiaoyaClient {
private token = '';
private baseURL: string;
constructor(
private baseURL: string,
baseURL: string,
private username?: string,
private password?: string,
private configToken?: string
) {}
) {
this.baseURL = normalizeApiBaseUrl(baseURL);
}
/**
* 使用账号密码登录获取Token
@@ -33,7 +38,8 @@ export class XiaoyaClient {
username: string,
password: string
): Promise<string> {
const response = await fetch(`${baseURL}/api/auth/login`, {
const normalizedBaseURL = normalizeApiBaseUrl(baseURL);
const response = await fetch(`${normalizedBaseURL}/api/auth/login`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',