统一API Base URL保存与请求时去除末尾斜杠
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user