-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (37 loc) · 798 Bytes
/
index.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
33
34
35
36
37
38
39
40
const express = require('express');
const app = express();
const GetMapping = (path) => {
return (target, name, descriptor) => {
const oldValue = descriptor.value;
descriptor.value = function() {
console.log(`GetMapping ${path}`)
return app.get(path, (req, res, next) => {
let result = oldValue.bind(this)(req, res, next);
if (result) {
if (typeof result === 'object') {
res.json(result);
} else {
res.send(result)
}
} else {
next();
}
});
}
descriptor.enumerable = true;
return descriptor;
}
}
const RestController = (target) => {
var cc = new target;
for (let key in target.prototype) {
cc[key]();
}
}
const requireDir = require('./lib/requireDir');
module.exports = {
app,
GetMapping,
RestController,
requireDir
};