-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
32 lines (27 loc) · 934 Bytes
/
app.js
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
'use strict';
const CallCollectHandler = require('./lib/call_collect_handler');
module.exports = class AppBootHook {
constructor(app) {
this.app = app;
this.app.config.appMiddleware.push('txHandler');
}
configWillLoad() {
this.app.routerCallMapping = new Map();
this._collectRouterCallInfo();
}
_collectRouterCallInfo() {
const routerCallMapping = this.app.routerCallMapping;
const router = this.app.router;
const proxyMethods = [ 'resources', 'get', 'post', 'put', 'delete', 'head', 'patch', 'options' ];
proxyMethods.forEach(method => {
if (Reflect.has(router, method)) {
const callCollectHandler = new CallCollectHandler(router, method, callMapping => {
callMapping.forEach((value, key) => {
routerCallMapping.set(key, value);
});
});
router[method] = new Proxy(router[method], callCollectHandler);
}
});
}
};