-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (35 loc) · 1003 Bytes
/
app.js
File metadata and controls
43 lines (35 loc) · 1003 Bytes
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
'use strict';
const { connect, closeConnection } = require('./lib/connect');
const { getConnectionOptions } = require('./lib/utils');
class AppBootHook {
constructor(app) {
this.app = app;
const config = app.config.typeorm;
if (!config) {
throw new Error('please config typeorm in config file');
}
}
/**
* 所有的配置已经加载完毕
* 可以用来加载应用自定义的文件,启动自定义的服务
*/
async didLoad() {
try {
this.app.logger.info('[typeorm]', 'start connect database');
const connectionOptions = getConnectionOptions(this.app);
await connect(this.app, connectionOptions);
this.app.logger.info('[typeorm]', 'connect database success');
} catch (error) {
this.app.logger.error('[typeorm]', 'connect database fail');
throw error;
}
}
/**
* 应用即将关闭
*/
async beforeClose() {
// 关闭连接
await closeConnection();
}
}
module.exports = AppBootHook;