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