-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.js
44 lines (34 loc) · 997 Bytes
/
plugin.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
/**
* Plugin.js file, set configs, routes, hooks and events here
*
* see http://wejs.org/docs/we/plugin
*/
module.exports = function loadPlugin(projectPath, Plugin) {
const plugin = new Plugin(__dirname);
// set plugin configs
plugin.setConfigs({
// Options: file, redis, rabitmq
sysPubsub: {
serviceName: 'file',
redisURL: process.env.REDIS_URL,
}
});
// set plugin routes
// plugin.setRoutes({
// });
plugin.selectPubSubService = function(we, done) {
const st = we.config.sysPubsub.serviceName;
if (!st) return done();
const Pubsub = require('./lib/pubsub/'+st);
we.sysPubsub = new Pubsub(we);
done();
};
plugin.initPubSub = function(we, done) {
if (!we.sysPubsub) return done();
we.sysPubsub.init(done);
we.events.emit('we:after:init:sysPubsub', we);
};
plugin.hooks.on('we:after:load:plugins', plugin.selectPubSubService);
plugin.hooks.on('we:models:ready', plugin.initPubSub);
return plugin;
};