midway-fatcms 0.0.1-beta.38 → 0.0.1-beta.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -61,13 +61,20 @@ export interface IUpstreamInfo {
|
|
|
61
61
|
targetList: IUpstreamItem[];
|
|
62
62
|
balanceStrategy: string;
|
|
63
63
|
}
|
|
64
|
+
export declare enum ProxyUserContextEnum {
|
|
65
|
+
NO_PASS = 0,
|
|
66
|
+
BASIC_INFO = 1,
|
|
67
|
+
SESSION_INFO = 2
|
|
68
|
+
}
|
|
64
69
|
export interface IProxyApiEntity extends IApiBaseEntity {
|
|
70
|
+
proxy_name: string;
|
|
71
|
+
proxy_code: string;
|
|
65
72
|
path_prefix: string;
|
|
66
73
|
upstream_code: string;
|
|
67
74
|
timeout_ms: number;
|
|
68
75
|
status: number;
|
|
69
76
|
workbench_code_array: string;
|
|
70
|
-
user_context:
|
|
77
|
+
user_context: ProxyUserContextEnum;
|
|
71
78
|
pass_real_ip: number;
|
|
72
79
|
change_origin: string;
|
|
73
80
|
change_host: string;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ProxyUserContextEnum = void 0;
|
|
4
|
+
var ProxyUserContextEnum;
|
|
5
|
+
(function (ProxyUserContextEnum) {
|
|
6
|
+
ProxyUserContextEnum[ProxyUserContextEnum["NO_PASS"] = 0] = "NO_PASS";
|
|
7
|
+
ProxyUserContextEnum[ProxyUserContextEnum["BASIC_INFO"] = 1] = "BASIC_INFO";
|
|
8
|
+
ProxyUserContextEnum[ProxyUserContextEnum["SESSION_INFO"] = 2] = "SESSION_INFO";
|
|
9
|
+
})(ProxyUserContextEnum = exports.ProxyUserContextEnum || (exports.ProxyUserContextEnum = {}));
|
|
@@ -16,11 +16,16 @@ const RouteTrie_1 = require("./RouteTrie");
|
|
|
16
16
|
const exceptions_1 = require("../../libs/crud-pro/exceptions");
|
|
17
17
|
const devops_1 = require("../../models/devops");
|
|
18
18
|
const CurdProService_1 = require("../curd/CurdProService");
|
|
19
|
+
const SystemEntities_1 = require("../../models/SystemEntities");
|
|
19
20
|
const axios_1 = require("axios");
|
|
20
21
|
const fatcms_request_1 = require("../../libs/utils/fatcms-request");
|
|
21
22
|
const ProxyApiUtils_1 = require("./ProxyApiUtils");
|
|
22
23
|
const ProxyApiLoadService_1 = require("./ProxyApiLoadService");
|
|
23
24
|
const ApiBaseService_1 = require("../base/ApiBaseService");
|
|
25
|
+
function toBase64(obj) {
|
|
26
|
+
const jsonString = JSON.stringify(obj);
|
|
27
|
+
return Buffer.from(jsonString, 'utf8').toString('base64');
|
|
28
|
+
}
|
|
24
29
|
/**
|
|
25
30
|
* 接口代理
|
|
26
31
|
*/
|
|
@@ -230,10 +235,25 @@ let ProxyApiService = class ProxyApiService extends ApiBaseService_1.ApiBaseServ
|
|
|
230
235
|
headers['x-real-ip'] = ctx.headers['x-real-ip'];
|
|
231
236
|
headers['x-forwarded-for'] = ctx.headers['x-forwarded-for'];
|
|
232
237
|
}
|
|
233
|
-
|
|
238
|
+
// 传递整个用户上下文
|
|
239
|
+
if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.SESSION_INFO) {
|
|
234
240
|
const isLogin = this.ctx.userSession.isLogin();
|
|
235
241
|
const sessionInfo = this.ctx.userSession.getSessionInfo();
|
|
236
|
-
headers['x-fatcms-
|
|
242
|
+
headers['x-fatcms-usercontext'] = toBase64({ ...sessionInfo, isLogin });
|
|
243
|
+
}
|
|
244
|
+
// 只传递用户基本信息
|
|
245
|
+
if (proxyApiEntity.user_context === SystemEntities_1.ProxyUserContextEnum.BASIC_INFO) {
|
|
246
|
+
const isLogin = this.ctx.userSession.isLogin();
|
|
247
|
+
const sessionInfo = this.ctx.userSession.getSessionInfo();
|
|
248
|
+
const userBasicInfo = { isLogin };
|
|
249
|
+
if (sessionInfo && isLogin) {
|
|
250
|
+
userBasicInfo.loginName = sessionInfo.loginName;
|
|
251
|
+
userBasicInfo.sessionId = sessionInfo.sessionId;
|
|
252
|
+
userBasicInfo.accountId = sessionInfo.accountId;
|
|
253
|
+
userBasicInfo.workbenchCode = sessionInfo.workbenchCode;
|
|
254
|
+
userBasicInfo.accountType = sessionInfo.accountType;
|
|
255
|
+
}
|
|
256
|
+
headers['x-fatcms-usercontext'] = toBase64(userBasicInfo);
|
|
237
257
|
}
|
|
238
258
|
if (proxyApiEntity.change_host && proxyApiEntity.change_host.length > 0) {
|
|
239
259
|
headers.host = proxyApiEntity.change_host;
|