fix cookie modules

This commit is contained in:
2026-02-06 02:02:41 +08:00
parent 236caed041
commit 183c0d5b77
4 changed files with 25 additions and 8 deletions

View File

@@ -27,6 +27,7 @@ export class CNBCore {
hackURL = API_HACK_URL;
public token: string;
public cookie?: string;
isCors: boolean;
constructor(options: CNBCoreOptions) {
this.token = options.token;
this.cookie = options.cookie;
@@ -42,6 +43,7 @@ export class CNBCore {
this.baseURL = options.cors.baseUrl + '/' + API_BASER_URL.replace('https://', '');
this.hackURL = options.cors.baseUrl + '/' + API_HACK_URL.replace('https://', '');
}
this.isCors = !!options?.cors?.baseUrl;
}
async request({ url, method = 'GET', data, params, headers, body, useCookie, useOrigin }: RequestOptions): Promise<any> {
@@ -70,10 +72,14 @@ export class CNBCore {
delete _headers.Authorization;
}
if (useCookie) {
_headers['Cookie'] = this.cookie || "";
if (this.isCors) {
_headers['app-cookie'] = this.cookie || "";
} else {
_headers['Cookie'] = this.cookie || "";
}
delete _headers.Authorization;
}
// console.log('Request URL:', url, data, _headers);
console.log('Request URL:', url, data, _headers);
const response = await fetch(url || '', {
method,
headers: _headers,