@zenweb/schedule 3.4.0 → 3.5.1
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.d.ts +0 -3
- package/dist/register.js +2 -25
- package/package.json +1 -1
package/dist/register.d.ts
CHANGED
package/dist/register.js
CHANGED
|
@@ -1,35 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ScheduleRegister = exports.schedule = void 0;
|
|
4
|
-
require("@zenweb/inject");
|
|
5
|
-
require("@zenweb/router");
|
|
6
|
-
require("@zenweb/log");
|
|
7
4
|
const http_1 = require("http");
|
|
8
5
|
const node_schedule_1 = require("node-schedule");
|
|
9
6
|
const crypto_1 = require("crypto");
|
|
10
7
|
const decorator_make_1 = require("decorator-make");
|
|
11
8
|
const router_1 = require("@zenweb/router");
|
|
12
9
|
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
10
|
const scheduleDecorator = (0, decorator_make_1.makeMethodDecorator)();
|
|
34
11
|
/**
|
|
35
12
|
* 定时任务设定
|
|
@@ -59,7 +36,7 @@ class ScheduleRegister {
|
|
|
59
36
|
(0, inject_1.scope)('prototype', false)(target);
|
|
60
37
|
for (const item of methods) {
|
|
61
38
|
// 添加到路由中
|
|
62
|
-
this.router.post(item.path,
|
|
39
|
+
this.router.post(item.path, ...(item.middleware ?
|
|
63
40
|
(Array.isArray(item.middleware) ? item.middleware : [item.middleware]) : []), async (ctx) => {
|
|
64
41
|
const cls = await ctx.injector.getInstance(target);
|
|
65
42
|
await ctx.injector.apply(cls, item);
|
|
@@ -84,7 +61,7 @@ class ScheduleRegister {
|
|
|
84
61
|
url: path,
|
|
85
62
|
path,
|
|
86
63
|
socket: {
|
|
87
|
-
remoteAddress:
|
|
64
|
+
remoteAddress: '127.0.0.1',
|
|
88
65
|
remotePort: 7001,
|
|
89
66
|
},
|
|
90
67
|
});
|