@zenweb/schedule 3.3.0 → 3.5.0
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/dist/register.js +3 -23
- package/package.json +3 -3
package/dist/register.js
CHANGED
|
@@ -10,26 +10,6 @@ const crypto_1 = require("crypto");
|
|
|
10
10
|
const decorator_make_1 = require("decorator-make");
|
|
11
11
|
const router_1 = require("@zenweb/router");
|
|
12
12
|
const inject_1 = require("@zenweb/inject");
|
|
13
|
-
const SAFE_IP = '127.0.0.1';
|
|
14
|
-
/**
|
|
15
|
-
* 安全检查,防止外部调用
|
|
16
|
-
*/
|
|
17
|
-
async function safeCheck(ctx, next) {
|
|
18
|
-
const startTime = Date.now();
|
|
19
|
-
ctx.log.info('start');
|
|
20
|
-
if (!ctx.req.socket.remoteAddress || !ctx.req.socket.remoteAddress.endsWith(SAFE_IP)) {
|
|
21
|
-
ctx.throw(403);
|
|
22
|
-
}
|
|
23
|
-
try {
|
|
24
|
-
await next();
|
|
25
|
-
}
|
|
26
|
-
catch (err) {
|
|
27
|
-
ctx.log.child({ err }).error('error');
|
|
28
|
-
}
|
|
29
|
-
finally {
|
|
30
|
-
ctx.log.info('end', Date.now() - startTime, 'ms');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
13
|
const scheduleDecorator = (0, decorator_make_1.makeMethodDecorator)();
|
|
34
14
|
/**
|
|
35
15
|
* 定时任务设定
|
|
@@ -59,7 +39,7 @@ class ScheduleRegister {
|
|
|
59
39
|
(0, inject_1.scope)('prototype', false)(target);
|
|
60
40
|
for (const item of methods) {
|
|
61
41
|
// 添加到路由中
|
|
62
|
-
this.router.post(item.path,
|
|
42
|
+
this.router.post(item.path, ...(item.middleware ?
|
|
63
43
|
(Array.isArray(item.middleware) ? item.middleware : [item.middleware]) : []), async (ctx) => {
|
|
64
44
|
const cls = await ctx.injector.getInstance(target);
|
|
65
45
|
await ctx.injector.apply(cls, item);
|
|
@@ -84,12 +64,12 @@ class ScheduleRegister {
|
|
|
84
64
|
url: path,
|
|
85
65
|
path,
|
|
86
66
|
socket: {
|
|
87
|
-
remoteAddress:
|
|
67
|
+
remoteAddress: '127.0.0.1',
|
|
88
68
|
remotePort: 7001,
|
|
89
69
|
},
|
|
90
70
|
});
|
|
91
71
|
const response = new http_1.ServerResponse(request);
|
|
92
|
-
this.core.
|
|
72
|
+
this.core.app.callback()(request, response);
|
|
93
73
|
});
|
|
94
74
|
this.jobs.push(job);
|
|
95
75
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zenweb/schedule",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Zenweb Schedule module",
|
|
5
5
|
"exports": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"url": "https://github.com/yefei/zenweb-schedule/issues"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@zenweb/core": "^3.
|
|
37
|
+
"@zenweb/core": "^3.3.0",
|
|
38
38
|
"@zenweb/inject": "^3.17.0",
|
|
39
|
-
"@zenweb/log": "^3.
|
|
39
|
+
"@zenweb/log": "^3.2.0",
|
|
40
40
|
"@zenweb/router": "^3.1.1",
|
|
41
41
|
"rimraf": "^4.3.1",
|
|
42
42
|
"ts-node": "^10.9.1",
|