-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathserver.js
61 lines (54 loc) · 1.63 KB
/
server.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const yapi = require('yapi.js');
const mongoose = require('mongoose');
const controller = require('./controller');
const InterfaceNotificationSender = require('./utils/interfaceNotificationSender');
const InterfaceModel = require('models/interface');
const Config = require('./utils/config');
const { SendLogViaDingDingSender } = require('./utils/logSender');
module.exports = function(options) {
Config.instance = options;
const originalSaveLog = this.commons.saveLog;
this.commons.saveLog = function() {
const args = Array.prototype.slice.call(arguments);
originalSaveLog.apply(this, args);
try {
yapi.commons.log('yapi-plugin-dingding: 开始运行');
const logData = args[0];
if (!logData || logData.type != 'project') {
yapi.commons.log('yapi-plugin-dingding: 日志不是 project 类型,跳过通知。');
return;
}
(new SendLogViaDingDingSender(logData)).send().then().catch((err) => {
yapi.commons.log(err, 'error');
});
} catch(err) {
yapi.commons.log(err, 'error');
}
}
yapi.connect.then(function() {
let db = mongoose.connection.db.collection('dding_robots');
db.createIndex({
project_id: 1
});
});
this.bindHook('add_router', function(router) {
router({
controller: controller,
method: 'get',
path: 'dding_robots/detail',
action: 'show'
});
router({
controller: controller,
method: 'post',
path: 'dding_robots/up',
action: 'update'
});
router({
controller: controller,
method: 'post',
path: 'dding_robots/test',
action: 'test'
});
});
}