-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.ts
126 lines (104 loc) · 2.52 KB
/
config.ts
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import * as dotenv from 'dotenv';
import * as _ from 'lodash';
import { injectable } from 'inversify';
import * as minimist from 'minimist';
// WARN: check for env file existance
dotenv.config();
// IMPROVE: integrate https://github.com/mozilla/node-convict
// TODO: parameters explanations
const defaultConf = {
debug: {
sendErrorsToClient: true,
sendStackToClient: true,
preventMailSending: process.env.SL_PREVENT_MAIL_SENDING === 'true' || false
},
google: {
geoUrl: 'https://maps.googleapis.com/maps/api/geocode/json',
token: process.env.SL_GOOGLE_TOKEN
},
http: {
port: 1337
},
log: {
http: true,
level: 'debug',
timestamp: true,
},
mail: {
apiKey: process.env.SL_MAILGUN_API_KEY,
domain: process.env.SL_MAILGUN_DOMAIN,
baseDomain: process.env.SL_MAIL_DOMAIN,
from: 'noreply@loscambialibri.it',
sendgridAPIKey: process.env.SL_SENDGRID_API_KEY
},
mongo: {
database: process.env.SL_MONGO_DB,
host: process.env.SL_MONGO_HOST,
password: process.env.SL_MONGO_PASSWORD,
user: process.env.SL_MONGO_USER
},
test: {
mongo: {
database: 'Scambialibri-test',
host: 'localhost',
password: null,
user: null
}
},
token: {
expiration: 2000000
}
};
@injectable()
export class Configuration {
log: {
timestamp: boolean;
level: string;
http: boolean;
};
google: {
geoUrl: string;
token: string;
};
mail: {
apiKey: string;
domain: string;
from: string;
baseDomain: string;
sendgridAPIKey: string;
};
mongo: {
user: string;
password: string;
host: string;
database: string;
};
http: {
port: number
};
token: {
expiration: number;
};
test: {
mongo: {
user: string;
password: string;
host: string;
database: string;
};
};
debug: {
sendStackToClient: boolean;
sendErrorsToClient: boolean;
preventMailSending: boolean;
};
constructor() {
const argv = minimist(process.argv.slice(2));
if (argv.port) defaultConf.http.port = argv.port;
this.setConfiguration();
}
setConfiguration(conf: object = {}) {
const c = _.merge(defaultConf, conf);
Object.assign(this, c);
}
}