model.js
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const compose = require('koa-compose');
class User {
constructor(uid, userAgent, path, ip) {
this._uid = uid;
this._userAgent = userAgent;
this._path = path;
this._ip = ip;
}
ip(opts) {
if (opts.excludes.includes(this._ip)) {
return null;
}
return this._ip;
}
}
class Resource {
all() {
return this;
}
includes(opts) {
}
excludes(opts) {
}
}
class Metrics {
qps(id, resource) {
}
}
function makeContext(req, res) {
const ctx = {req, res};
return ctx;
}
const _rules = [];
function runRule() {
const middleWare = compose(_rules);
return (req, res, next) => {
const context = makeContext(req, res);
middleWare(context).then(() => {
res.json({
code: 200,
message: '成功'
});
}).catch(next);
};
}
function addRule(name, opts, action) {
_rules.push(action.bind(opts));
}
module.exports = {
rule: addRule,
runRule
};