1 | "use strict";
|
2 |
|
3 | const debug = require("debug")("motif:config");
|
4 | const fs = require("fs");
|
5 | const path = require("path");
|
6 |
|
7 | const DAO = require("node-data-access-object");
|
8 |
|
9 | class Config {
|
10 | get mode() {
|
11 | return this._mode;
|
12 | }
|
13 |
|
14 | get database() {
|
15 | return this._config.database || {};
|
16 | }
|
17 |
|
18 | get tokenSecret() {
|
19 | return (this._config.jwt && this._config.jwt.tokenSecret) || "secure";
|
20 | }
|
21 |
|
22 | get tokenAlgorithm() {
|
23 | return (this._config.jwt && this._config.jwt.tokenAlgorithm) || "HS256";
|
24 | }
|
25 |
|
26 | get expiresTokenIn() {
|
27 | return (
|
28 | (this._config.jwt && this._config.jwt.expiresTokenIn) || 60 * 60 * 24 * 7
|
29 | );
|
30 | }
|
31 |
|
32 | get refreshsTokenIn() {
|
33 | return (
|
34 | (this._config.jwt && this._config.jwt.refreshsTokenIn) || 60 * 60 * 24 * 2
|
35 | );
|
36 | }
|
37 |
|
38 | get jwt() {
|
39 | return this._config.jwt || {};
|
40 | }
|
41 |
|
42 | get aws() {
|
43 | return this._config.aws || {};
|
44 | }
|
45 |
|
46 | get(name) {
|
47 | return this._config[name];
|
48 | }
|
49 |
|
50 | constructor(options) {
|
51 | debug("config", options);
|
52 |
|
53 | const {mode} = options;
|
54 | const appPath = path.resolve(process.env.PWD, ".");
|
55 | const content = fs.readFileSync(
|
56 | appPath + "/config/conf.d/config." + mode + ".json"
|
57 | );
|
58 |
|
59 | this._appPath = appPath;
|
60 | this._mode = mode;
|
61 | this._config = JSON.parse(content);
|
62 | }
|
63 |
|
64 | connection(key) {
|
65 | return DAO.connection(key);
|
66 | }
|
67 |
|
68 | registerConnnection(key, options) {
|
69 | DAO.registerConnnection(key, options);
|
70 | }
|
71 | }
|
72 |
|
73 | module.exports = Config;
|