@jayfong/x-server 2.49.0 → 2.49.3
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/cli/build_util.js +20 -12
- package/lib/_cjs/cli/cli.js +0 -0
- package/lib/_cjs/core/handler.js +34 -25
- package/lib/_cjs/core/http_header.js +3 -5
- package/lib/_cjs/core/http_method.js +2 -3
- package/lib/_cjs/core/server.js +1 -2
- package/lib/_cjs/core/types.js +4 -12
- package/lib/_cjs/x.js +1 -2
- package/lib/cli/build_util.js +20 -12
- package/lib/core/define_bus.js +2 -0
- package/lib/core/handler.js +34 -25
- package/lib/core/server.js +1 -2
- package/lib/core/types.js +1 -5
- package/package.json +1 -1
|
@@ -29,7 +29,9 @@ class BuildUtil {
|
|
|
29
29
|
await _fsExtra.default.ensureDir(tempDir);
|
|
30
30
|
|
|
31
31
|
// 处理 external
|
|
32
|
-
const external = (0, _vtils.uniq)(options.external || [])
|
|
32
|
+
const external = (0, _vtils.uniq)([...(options.external || []),
|
|
33
|
+
// bull 始终作为外部依赖
|
|
34
|
+
'bull']);
|
|
33
35
|
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
34
36
|
try {
|
|
35
37
|
// 为何不用 require.resolve:
|
|
@@ -91,17 +93,23 @@ class BuildUtil {
|
|
|
91
93
|
loader: 'js'
|
|
92
94
|
};
|
|
93
95
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
96
|
+
|
|
97
|
+
// build.onLoad(
|
|
98
|
+
// { filter: /\/bull\/lib\/commands\/index\.js$/ },
|
|
99
|
+
// async args => {
|
|
100
|
+
// let js = await fs.readFile(args.path, 'utf-8');
|
|
101
|
+
// js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
102
|
+
// await fs.copy(
|
|
103
|
+
// path.dirname(require.resolve('bull/lib/commands/index.js')),
|
|
104
|
+
// path.join(distDir, 'assets/bull/commands'),
|
|
105
|
+
// );
|
|
106
|
+
// return {
|
|
107
|
+
// contents: js,
|
|
108
|
+
// loader: 'js',
|
|
109
|
+
// };
|
|
110
|
+
// },
|
|
111
|
+
// );
|
|
112
|
+
|
|
105
113
|
build.onLoad({
|
|
106
114
|
filter: /\/vm2\/lib\/vm\.js$/
|
|
107
115
|
}, async args => {
|
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
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.log('服务器错误', 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();
|
|
@@ -19,7 +19,7 @@ ${'/'}**
|
|
|
19
19
|
${item.pascalName} = '${item.name}',
|
|
20
20
|
`).join('\n\n')
|
|
21
21
|
*/
|
|
22
|
-
let HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
22
|
+
let HttpRequestHeader = exports.HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
23
23
|
HttpRequestHeader["A_IM"] = "A-IM";
|
|
24
24
|
HttpRequestHeader["ACCEPT"] = "Accept";
|
|
25
25
|
HttpRequestHeader["ACCEPT_CHARSET"] = "Accept-Charset";
|
|
@@ -78,8 +78,7 @@ let HttpRequestHeader = /*#__PURE__*/function (HttpRequestHeader) {
|
|
|
78
78
|
HttpRequestHeader["SAVE_DATA"] = "Save-Data";
|
|
79
79
|
return HttpRequestHeader;
|
|
80
80
|
}({});
|
|
81
|
-
exports.
|
|
82
|
-
let HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
81
|
+
let HttpResponseHeader = exports.HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
83
82
|
HttpResponseHeader["ACCESS_CONTROL_ALLOW_ORIGIN"] = "Access-Control-Allow-Origin";
|
|
84
83
|
HttpResponseHeader["ACCESS_CONTROL_ALLOW_CREDENTIALS"] = "Access-Control-Allow-Credentials";
|
|
85
84
|
HttpResponseHeader["ACCESS_CONTROL_EXPOSE_HEADERS"] = "Access-Control-Expose-Headers";
|
|
@@ -140,5 +139,4 @@ let HttpResponseHeader = /*#__PURE__*/function (HttpResponseHeader) {
|
|
|
140
139
|
HttpResponseHeader["X_UA_COMPATIBLE"] = "X-UA-Compatible";
|
|
141
140
|
HttpResponseHeader["X_XSS_PROTECTION"] = "X-XSS-Protection";
|
|
142
141
|
return HttpResponseHeader;
|
|
143
|
-
}({});
|
|
144
|
-
exports.HttpResponseHeader = HttpResponseHeader;
|
|
142
|
+
}({});
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.HandlerMethodToHttpMethod = void 0;
|
|
5
|
-
const HandlerMethodToHttpMethod = {
|
|
5
|
+
const HandlerMethodToHttpMethod = exports.HandlerMethodToHttpMethod = {
|
|
6
6
|
GET: 'GET',
|
|
7
7
|
POST: 'POST',
|
|
8
8
|
FILE: 'POST',
|
|
9
9
|
WS: 'GET',
|
|
10
10
|
XML: 'POST'
|
|
11
|
-
};
|
|
12
|
-
exports.HandlerMethodToHttpMethod = HandlerMethodToHttpMethod;
|
|
11
|
+
};
|
package/lib/_cjs/core/server.js
CHANGED
|
@@ -78,8 +78,7 @@ class Server {
|
|
|
78
78
|
const handlerOptions = item.handler.options;
|
|
79
79
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
80
80
|
const isWS = handlerMethod === 'WS';
|
|
81
|
-
const url = `${appUrl}${
|
|
82
|
-
// 结构:/test/sss?x=2
|
|
81
|
+
const url = `${appUrl}${// 结构:/test/sss?x=2
|
|
83
82
|
path != null ? path : isWS ? res.url : req.url}`;
|
|
84
83
|
if (isWS) {
|
|
85
84
|
await item.handler.handle(undefined, {
|
package/lib/_cjs/core/types.js
CHANGED
|
@@ -2,15 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.XTask = exports.XServer = exports.XHandler = exports.XCron = void 0;
|
|
5
|
-
let XServer;
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
let
|
|
9
|
-
exports.XHandler = XHandler;
|
|
10
|
-
(function (_XHandler) {})(XHandler || (exports.XHandler = XHandler = {}));
|
|
11
|
-
let XTask;
|
|
12
|
-
exports.XTask = XTask;
|
|
13
|
-
(function (_XTask) {})(XTask || (exports.XTask = XTask = {}));
|
|
14
|
-
let XCron;
|
|
15
|
-
exports.XCron = XCron;
|
|
16
|
-
(function (_XCron) {})(XCron || (exports.XCron = XCron = {}));
|
|
5
|
+
let XServer = exports.XServer = void 0;
|
|
6
|
+
let XHandler = exports.XHandler = void 0;
|
|
7
|
+
let XTask = exports.XTask = void 0;
|
|
8
|
+
let XCron = exports.XCron = void 0;
|
package/lib/_cjs/x.js
CHANGED
|
@@ -10,7 +10,7 @@ var _dispose = require("./services/dispose");
|
|
|
10
10
|
var _emoji = require("./services/emoji");
|
|
11
11
|
var _log = require("./services/log");
|
|
12
12
|
const env = JSON.parse(process.env.X_SERVER_ENVS || '{}');
|
|
13
|
-
const x = {
|
|
13
|
+
const x = exports.x = {
|
|
14
14
|
appId: env.APP_ID,
|
|
15
15
|
env: env,
|
|
16
16
|
dataDir: _path.default.join(_os.default.homedir(), `.xs/${env.APP_ID}`),
|
|
@@ -21,7 +21,6 @@ const x = {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
exports.x = x;
|
|
25
24
|
_fsExtra.default.ensureDirSync(x.dataDir);
|
|
26
25
|
x.register(new _dispose.DisposeService({
|
|
27
26
|
disposeOnExit: true
|
package/lib/cli/build_util.js
CHANGED
|
@@ -23,7 +23,9 @@ export class BuildUtil {
|
|
|
23
23
|
await fs.ensureDir(tempDir);
|
|
24
24
|
|
|
25
25
|
// 处理 external
|
|
26
|
-
const external = uniq(options.external || [])
|
|
26
|
+
const external = uniq([...(options.external || []),
|
|
27
|
+
// bull 始终作为外部依赖
|
|
28
|
+
'bull']);
|
|
27
29
|
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
28
30
|
try {
|
|
29
31
|
// 为何不用 require.resolve:
|
|
@@ -85,17 +87,23 @@ export class BuildUtil {
|
|
|
85
87
|
loader: 'js'
|
|
86
88
|
};
|
|
87
89
|
});
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
|
|
91
|
+
// build.onLoad(
|
|
92
|
+
// { filter: /\/bull\/lib\/commands\/index\.js$/ },
|
|
93
|
+
// async args => {
|
|
94
|
+
// let js = await fs.readFile(args.path, 'utf-8');
|
|
95
|
+
// js = js.replace(/__dirname/g, '"./assets/bull/commands"');
|
|
96
|
+
// await fs.copy(
|
|
97
|
+
// path.dirname(require.resolve('bull/lib/commands/index.js')),
|
|
98
|
+
// path.join(distDir, 'assets/bull/commands'),
|
|
99
|
+
// );
|
|
100
|
+
// return {
|
|
101
|
+
// contents: js,
|
|
102
|
+
// loader: 'js',
|
|
103
|
+
// };
|
|
104
|
+
// },
|
|
105
|
+
// );
|
|
106
|
+
|
|
99
107
|
build.onLoad({
|
|
100
108
|
filter: /\/vm2\/lib\/vm\.js$/
|
|
101
109
|
}, async args => {
|
package/lib/core/define_bus.js
CHANGED
|
@@ -21,5 +21,7 @@ export function defineBus() {
|
|
|
21
21
|
// Unfortunately, this has the result of giving a poor error message when
|
|
22
22
|
// you mix up types.
|
|
23
23
|
// 0: https://github.com/Microsoft/TypeScript/issues/26013)
|
|
24
|
+
|
|
24
25
|
// TODO: Stash under a symbol key once TS compiler bug is fixed
|
|
26
|
+
|
|
25
27
|
// EventEmitter method overrides
|
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.log('服务器错误', 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();
|
package/lib/core/server.js
CHANGED
|
@@ -72,8 +72,7 @@ export class Server {
|
|
|
72
72
|
const handlerOptions = item.handler.options;
|
|
73
73
|
const handlerMethod = handlerOptions.requestMethod || 'POST';
|
|
74
74
|
const isWS = handlerMethod === 'WS';
|
|
75
|
-
const url = `${appUrl}${
|
|
76
|
-
// 结构:/test/sss?x=2
|
|
75
|
+
const url = `${appUrl}${// 结构:/test/sss?x=2
|
|
77
76
|
path != null ? path : isWS ? res.url : req.url}`;
|
|
78
77
|
if (isWS) {
|
|
79
78
|
await item.handler.handle(undefined, {
|
package/lib/core/types.js
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export let XServer;
|
|
2
|
-
(function (_XServer) {})(XServer || (XServer = {}));
|
|
3
2
|
export let XHandler;
|
|
4
|
-
(function (_XHandler) {})(XHandler || (XHandler = {}));
|
|
5
3
|
export let XTask;
|
|
6
|
-
|
|
7
|
-
export let XCron;
|
|
8
|
-
(function (_XCron) {})(XCron || (XCron = {}));
|
|
4
|
+
export let XCron;
|