-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
32 lines (30 loc) · 815 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 Controller = require('egg').Controller;
module.exports = app => {
app.BaseController = class BaseController extends Controller {
index() {
app.index += 1;
return app.index;
}
success(data) {
this.ctx.body = data;
}
fail(data) {
const ret = data || { status: false, message: '参数错误' };
this.ctx.body = ret;
this.ctx.status = 500;
}
res(data) {
console.log('第'+app.index+'次响应');
if (data.status) {
this.success(data);
} else {
this.fail(data);
}
}
};
app.beforeStart(async () => {
console.log('启动好啦');
app.index = 1;
});
};