fix cookie modules
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user