forked from doramart/DoraCMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
65 lines (53 loc) · 2.15 KB
/
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
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
62
63
64
65
const path = require('path');
var Cache = require('js-cache');
class AppBootHook {
constructor(app) {
this.app = app;
}
beforeStart() {
this.app.runSchedule('backup_data');
}
configWillLoad() {
this.app.loader.loadFile(path.join(this.app.config.baseDir, 'app/bootstrap/index.js'));
const ctx = this.app.createAnonymousContext();
this.app.nunjucks.addExtension('remote', new remote(ctx));
this.app.nunjucks.addExtension('HeaderExtension', new HeaderExtension(ctx));
this.app.nunjucks.addExtension('AssetsExtension', new AssetsExtension(ctx));
this.app.nunjucks.addExtension('PluginsExtension', new PluginsExtension(ctx));
this.app.nunjucks.addExtension('recommend', new recommend(ctx));
this.app.nunjucks.addExtension('hot', new hot(ctx));
this.app.nunjucks.addExtension('news', new news(ctx));
this.app.nunjucks.addExtension('random', new random(ctx));
this.app.nunjucks.addExtension('near_post', new near_post(ctx));
this.app.nunjucks.addExtension('tags', new tags(ctx));
this.app.nunjucks.addExtension('hottags', new hottags(ctx));
this.app.nunjucks.addExtension('ads', new ads(ctx));
this.app.nunjucks.addExtension('navtree', new navtree(ctx));
this.app.nunjucks.addExtension('childnav', new childnav(ctx));
}
async didLoad() {
}
async willReady() {
// 请将你的应用项目中 app.beforeStart 中的代码置于此处。
}
async didReady() {
let _theApp = this.app;
_theApp.cache = new Cache();
_theApp.messenger.on('refreshCache', by => {
_theApp.logger.info('start update by %s', by);
const ctx = _theApp.createAnonymousContext();
ctx.runInBackground(async () => {
let {
key,
value,
time
} = by;
_theApp.cache.set(key, value, time);
});
});
// 应用初始化
let thisCtx = this.app.createAnonymousContext();
this.app.init(thisCtx);
}
}
module.exports = AppBootHook;