forked from oSoc18/Octotrails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
51 lines (47 loc) · 1.51 KB
/
config.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
45
46
47
48
49
50
51
import Joi from 'joi';
// require and configure dotenv, will load vars in .env in PROCESS.ENV
require('dotenv').config();
// Define a Schema for the env vars
const envVarsSchema = Joi.object({
NODE_ENV: Joi.string()
.allow(['development', 'production', 'test', 'provision'])
.default('development'),
SERVER_PORT: Joi.number().default(8081),
MONGOOSE_DEBUG: Joi.boolean().when('NODE_ENV', {
is: Joi.string().equal('development'),
then: Joi.boolean().default(true),
otherwise: Joi.boolean().default(false)
}),
JWT_SECRET: Joi.string()
.description('JWT Secret required to sign')
.default('58d49jQc5E=6854099462989ef034a5+ihvhOjbWoa65A'),
MONGO_HOST: Joi.string()
.description('Mongo DB host url')
.default('mongodb://localhost:27017/test-octotrails'),
MONGO_PORT: Joi.number().default(27017),
STIB_API: Joi.string()
.description('STIB API url')
.default(
'https://proxy.sulliops.co/index.php?http://detobel36.ddns.net/files/osoc/'
)
})
.unknown()
.required();
const { error, value: envVars } = Joi.validate(process.env, envVarsSchema);
if (error) {
throw new Error(`Config validation error: ${error.message}`);
}
// Config to be shared in the web-api
const config = {
isProd: envVars.NODE_ENV === 'production',
env: envVars.NODE_ENV,
port: envVars.SERVER_PORT,
mongooseDebug: envVars.MONGOOSE_DEBUG,
jwtSecret: envVars.JWT_SECRET,
mongo: {
host: envVars.MONGO_HOST,
port: envVars.MONGO_PORT
},
stibApi: envVars.STIB_API
};
export default config;