diff --git a/package.json b/package.json index 684dcbd..3fabd4a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@kevisual/cnb", - "version": "0.0.18", + "version": "0.0.19", "description": "", "main": "index.js", "scripts": { diff --git a/src/cnb-core.ts b/src/cnb-core.ts index fb27784..e7eb2c9 100644 --- a/src/cnb-core.ts +++ b/src/cnb-core.ts @@ -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 { @@ -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, diff --git a/test/get-ueserinfo.ts b/test/get-ueserinfo.ts index 9800eab..1e8fa34 100644 --- a/test/get-ueserinfo.ts +++ b/test/get-ueserinfo.ts @@ -1,3 +1,14 @@ -import { cnb, showMore } from './common.ts'; -const res = await cnb.user.getCurrentUser(); -console.log("get-ueserinfo: getCurrentUser", res); \ No newline at end of file +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); diff --git a/test/issue.ts b/test/issue.ts index eaa3dd6..19304fd 100644 --- a/test/issue.ts +++ b/test/issue.ts @@ -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", {