fix cookie modules
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/cnb",
|
"name": "@kevisual/cnb",
|
||||||
"version": "0.0.18",
|
"version": "0.0.19",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ export class CNBCore {
|
|||||||
hackURL = API_HACK_URL;
|
hackURL = API_HACK_URL;
|
||||||
public token: string;
|
public token: string;
|
||||||
public cookie?: string;
|
public cookie?: string;
|
||||||
|
isCors: boolean;
|
||||||
constructor(options: CNBCoreOptions) {
|
constructor(options: CNBCoreOptions) {
|
||||||
this.token = options.token;
|
this.token = options.token;
|
||||||
this.cookie = options.cookie;
|
this.cookie = options.cookie;
|
||||||
@@ -42,6 +43,7 @@ export class CNBCore {
|
|||||||
this.baseURL = options.cors.baseUrl + '/' + API_BASER_URL.replace('https://', '');
|
this.baseURL = options.cors.baseUrl + '/' + API_BASER_URL.replace('https://', '');
|
||||||
this.hackURL = options.cors.baseUrl + '/' + API_HACK_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> {
|
async request({ url, method = 'GET', data, params, headers, body, useCookie, useOrigin }: RequestOptions): Promise<any> {
|
||||||
@@ -70,10 +72,14 @@ export class CNBCore {
|
|||||||
delete _headers.Authorization;
|
delete _headers.Authorization;
|
||||||
}
|
}
|
||||||
if (useCookie) {
|
if (useCookie) {
|
||||||
|
if (this.isCors) {
|
||||||
|
_headers['app-cookie'] = this.cookie || "";
|
||||||
|
} else {
|
||||||
_headers['Cookie'] = this.cookie || "";
|
_headers['Cookie'] = this.cookie || "";
|
||||||
|
}
|
||||||
delete _headers.Authorization;
|
delete _headers.Authorization;
|
||||||
}
|
}
|
||||||
// console.log('Request URL:', url, data, _headers);
|
console.log('Request URL:', url, data, _headers);
|
||||||
const response = await fetch(url || '', {
|
const response = await fetch(url || '', {
|
||||||
method,
|
method,
|
||||||
headers: _headers,
|
headers: _headers,
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
import { cnb, showMore } from './common.ts';
|
import { cnb, showMore, cookie, token } from './common.ts';
|
||||||
const res = await cnb.user.getCurrentUser();
|
import { User } from '../src';
|
||||||
console.log("get-ueserinfo: getCurrentUser", res);
|
// 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,
|
token: token, cookie: cookie,
|
||||||
cors: {
|
cors: {
|
||||||
// baseUrl: 'http://localhost:8080'
|
// baseUrl: 'http://localhost:8080'
|
||||||
// baseUrl: 'https://cors.kevisual.cn'
|
baseUrl: 'https://cors.kevisual.cn'
|
||||||
baseUrl: 'http://cors.kevisual.cn:11111'
|
// baseUrl: 'http://cors.kevisual.cn:11111'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// const res = await issue.createIssue("cnb", {
|
// const res = await issue.createIssue("cnb", {
|
||||||
|
|||||||
Reference in New Issue
Block a user