import Joi from 'joi';
// require and configure dotenv, will load vars in .env in PROCESS.ENV
require('dotenv').config();

// define validation for all the env vars
const envVarsSchema = Joi.object({
  NODE_ENV: Joi.string()
    .allow(['development', 'production', 'test', 'provision'])
    .default('development'),
  PORT: Joi.number()
    .default(3000),
  JWT_SECRET: Joi.string().required()
    .description('JWT Secret required to sign'),
  DB_URI: Joi.string().required()
    .description('SQL DB full uri'),
  MAILGUN_KEY: Joi.string().required()
    .description('Mail Gun Secret Key')
}).unknown()
  .required();

const { error, value: envVars } = Joi.validate(process.env, envVarsSchema);
if (error) {
  throw new Error(`Config validation error: ${error.message}`);
}

const config = {
  env: envVars.NODE_ENV,
  port: envVars.PORT,
  sqlDebug: envVars.SQL_DEBUG,
  jwtSecret: envVars.JWT_SECRET,
  mailgun_key: envVars.MAILGUN_KEY,
  s3_key: envVars.AWS_S3_KEY,
  s3_secret: envVars.AWS_S3_SECRET,
  mongoUri: envVars.DB_URI
};

export default config;

@@ -509,16 +509,89 @@
  uri'),%0A
+  MONGODB_URI: Joi.string().required()%0A    .description('Mongo DB URI'),%0A
   MAILGU
@@ -974,16 +974,41 @@
 SECRET,%0A
+  dbUri: envVars.DB_URI,%0A
   mailgu
@@ -1117,24 +1117,29 @@
 ri: envVars.
+MONGO
 DB_URI%0A%7D;%0A%0Ae

revert config misname