1 | const EventEmitter = require("eventemitter3")
|
2 | const sprintf = require("sprintf-js").sprintf
|
3 |
|
4 | class Base {
|
5 |
|
6 | constructor(container) {
|
7 | EventEmitter.call(this)
|
8 | this.container = container
|
9 | this.routes = require("./routes")
|
10 | }
|
11 |
|
12 | getRoutes() {
|
13 | return this.routes
|
14 | }
|
15 |
|
16 | |
17 |
|
18 |
|
19 | route(key) {
|
20 | var args = Array.prototype.slice.call(arguments)
|
21 | args[0] = this.getRoutes()[ key ] || key
|
22 | return sprintf(...args)
|
23 | }
|
24 |
|
25 | getClient() {
|
26 | return this.getContainer().getClient()
|
27 | }
|
28 |
|
29 | getConfig() {
|
30 | return this.getContainer().getConfig()
|
31 | }
|
32 |
|
33 | setConfig(c) {
|
34 | return this.getContainer().setConfig(c)
|
35 | }
|
36 |
|
37 | getContainer() {
|
38 | if(!this.container) {
|
39 | throw new Error("container is not available")
|
40 | }
|
41 | return this.container
|
42 | }
|
43 |
|
44 | }
|
45 |
|
46 | module.exports = Base
|