@jayfong/x-server 2.49.2 → 2.49.4
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.
- package/lib/_cjs/core/handler.js +34 -25
- package/lib/core/handler.js +34 -25
- package/package.json +1 -1
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -61,38 +61,47 @@ class Handler {
|
|
|
61
61
|
throw new _http_error.HttpError.BadRequest(err.message);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
// 设置响应的 Content-Type 头
|
|
71
|
-
if (this.options.responseContentType) {
|
|
72
|
-
ctx.setHeader('Content-Type', this.options.responseContentType);
|
|
73
|
-
}
|
|
64
|
+
try {
|
|
65
|
+
let res = await this.options.handle(data, ctx);
|
|
66
|
+
if (res instanceof _http_redirect.HttpRedirect) {
|
|
67
|
+
ctx.redirect(res.url, res.permanently);
|
|
68
|
+
return {};
|
|
69
|
+
}
|
|
74
70
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
71
|
+
// 设置响应的 Content-Type 头
|
|
72
|
+
if (this.options.responseContentType) {
|
|
73
|
+
ctx.setHeader('Content-Type', this.options.responseContentType);
|
|
74
|
+
}
|
|
79
75
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
};
|
|
85
|
-
}
|
|
76
|
+
// 打包返回数据
|
|
77
|
+
if (this.options.responseDataPack) {
|
|
78
|
+
res = _vtils.DataPacker.packAsRawType(res);
|
|
79
|
+
}
|
|
86
80
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (_server.Server.options.responseEncryptAlgorithm === 'simple') {
|
|
81
|
+
// 混淆返回数据
|
|
82
|
+
if (this.options.responseDataObfuscate) {
|
|
90
83
|
res = {
|
|
91
|
-
_
|
|
84
|
+
'_#': _lzString.default.compress(JSON.stringify(res))
|
|
92
85
|
};
|
|
93
86
|
}
|
|
87
|
+
|
|
88
|
+
// 加密返回数据
|
|
89
|
+
if (this.options.responseDataEncrypt && _server.Server.options.responseEncryptAlgorithm) {
|
|
90
|
+
if (_server.Server.options.responseEncryptAlgorithm === 'simple') {
|
|
91
|
+
res = {
|
|
92
|
+
_$: (0, _vtils.rot13)((0, _vtils.base64UrlEncode)(`${Date.now()}${JSON.stringify(res)}`))
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return res == null ? {} : res;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
// 业务错误
|
|
99
|
+
if (_http_error.HttpError.isHttpError(err)) {
|
|
100
|
+
throw err;
|
|
101
|
+
}
|
|
102
|
+
console.error('服务器错误', err);
|
|
103
|
+
throw new _http_error.HttpError.InternalServerError('服务异常,请稍后再试');
|
|
94
104
|
}
|
|
95
|
-
return res == null ? {} : res;
|
|
96
105
|
};
|
|
97
106
|
this.handleWs = async (_data, ctx) => {
|
|
98
107
|
const dispose = new _dispose.DisposeService();
|
package/lib/core/handler.js
CHANGED
|
@@ -55,38 +55,47 @@ export class Handler {
|
|
|
55
55
|
throw new HttpError.BadRequest(err.message);
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// 设置响应的 Content-Type 头
|
|
65
|
-
if (this.options.responseContentType) {
|
|
66
|
-
ctx.setHeader('Content-Type', this.options.responseContentType);
|
|
67
|
-
}
|
|
58
|
+
try {
|
|
59
|
+
let res = await this.options.handle(data, ctx);
|
|
60
|
+
if (res instanceof HttpRedirect) {
|
|
61
|
+
ctx.redirect(res.url, res.permanently);
|
|
62
|
+
return {};
|
|
63
|
+
}
|
|
68
64
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
// 设置响应的 Content-Type 头
|
|
66
|
+
if (this.options.responseContentType) {
|
|
67
|
+
ctx.setHeader('Content-Type', this.options.responseContentType);
|
|
68
|
+
}
|
|
73
69
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
}
|
|
70
|
+
// 打包返回数据
|
|
71
|
+
if (this.options.responseDataPack) {
|
|
72
|
+
res = DataPacker.packAsRawType(res);
|
|
73
|
+
}
|
|
80
74
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (Server.options.responseEncryptAlgorithm === 'simple') {
|
|
75
|
+
// 混淆返回数据
|
|
76
|
+
if (this.options.responseDataObfuscate) {
|
|
84
77
|
res = {
|
|
85
|
-
_
|
|
78
|
+
'_#': LZString.compress(JSON.stringify(res))
|
|
86
79
|
};
|
|
87
80
|
}
|
|
81
|
+
|
|
82
|
+
// 加密返回数据
|
|
83
|
+
if (this.options.responseDataEncrypt && Server.options.responseEncryptAlgorithm) {
|
|
84
|
+
if (Server.options.responseEncryptAlgorithm === 'simple') {
|
|
85
|
+
res = {
|
|
86
|
+
_$: rot13(base64UrlEncode(`${Date.now()}${JSON.stringify(res)}`))
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return res == null ? {} : res;
|
|
91
|
+
} catch (err) {
|
|
92
|
+
// 业务错误
|
|
93
|
+
if (HttpError.isHttpError(err)) {
|
|
94
|
+
throw err;
|
|
95
|
+
}
|
|
96
|
+
console.error('服务器错误', err);
|
|
97
|
+
throw new HttpError.InternalServerError('服务异常,请稍后再试');
|
|
88
98
|
}
|
|
89
|
-
return res == null ? {} : res;
|
|
90
99
|
};
|
|
91
100
|
this.handleWs = async (_data, ctx) => {
|
|
92
101
|
const dispose = new DisposeService();
|