fix cookie modules
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/cnb",
|
||||
"version": "0.0.18",
|
||||
"version": "0.0.19",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,3 +1,14 @@
|
||||
import { cnb, showMore } from './common.ts';
|
||||
const res = await cnb.user.getCurrentUser();
|
||||
console.log("get-ueserinfo: getCurrentUser", res);
|
||||
import { cnb, showMore, cookie, token } from './common.ts';
|
||||
import { User } from '../src';
|
||||
// const res = await cnb.user.getCurrentUser();
|
||||
// console.log("get-ueserinfo: getCurrentUser", res);
|
||||
|
||||
const user = new User({
|
||||
token, cookie,
|
||||
cors: {
|
||||
baseUrl: 'https://cors.kevisual.cn'
|
||||
}
|
||||
})
|
||||
|
||||
const res2 = await user.getCurrentUser()
|
||||
console.log("get-ueserinfo: getCurrentUser", res2);
|
||||
|
||||
@@ -6,8 +6,8 @@ const issue = new Issue({
|
||||
token: token, cookie: cookie,
|
||||
cors: {
|
||||
// baseUrl: 'http://localhost:8080'
|
||||
// baseUrl: 'https://cors.kevisual.cn'
|
||||
baseUrl: 'http://cors.kevisual.cn:11111'
|
||||
baseUrl: 'https://cors.kevisual.cn'
|
||||
// baseUrl: 'http://cors.kevisual.cn:11111'
|
||||
}
|
||||
});
|
||||
// const res = await issue.createIssue("cnb", {
|
||||
|
||||
Reference in New Issue
Block a user