2020-12-09 18:42:51 +00:00
|
|
|
import { config as configDotenv } from 'dotenv';
|
2021-01-15 18:18:23 +00:00
|
|
|
import { CountryCode } from 'libphonenumber-js';
|
2020-12-22 11:38:53 +00:00
|
|
|
import ValidatorJS from 'validator';
|
|
|
|
|
2020-12-09 18:42:51 +00:00
|
|
|
configDotenv();
|
|
|
|
export const config = {
|
|
|
|
internal_port: parseInt(process.env.APP_PORT) || 4010,
|
|
|
|
development: process.env.NODE_ENV === "production",
|
|
|
|
jwt_secret: process.env.JWT_SECRET || "secretjwtsecret",
|
2021-01-15 18:18:23 +00:00
|
|
|
phone_validation_countrycode: getPhoneCodeLocale(),
|
2021-01-12 16:39:40 +00:00
|
|
|
postalcode_validation_countrycode: getPostalCodeLocale(),
|
2021-01-20 16:25:46 +00:00
|
|
|
version: process.env.VERSION || require('../package.json').version,
|
2021-01-26 15:09:11 +00:00
|
|
|
seedTestData: getDataSeeding(),
|
2021-01-26 17:31:34 +00:00
|
|
|
app_url: process.env.APP_URL || "http://localhost:4010",
|
2021-01-26 15:09:11 +00:00
|
|
|
mail_server: process.env.MAIL_SERVER,
|
2021-01-26 16:20:33 +00:00
|
|
|
mail_port: Number(process.env.MAIL_PORT) || 25,
|
2021-01-26 15:09:11 +00:00
|
|
|
mail_user: process.env.MAIL_USER,
|
|
|
|
mail_password: process.env.MAIL_PASSWORD,
|
|
|
|
mail_from: process.env.MAIL_FROM
|
2020-12-09 18:42:51 +00:00
|
|
|
}
|
|
|
|
let errors = 0
|
|
|
|
if (typeof config.internal_port !== "number") {
|
|
|
|
errors++
|
|
|
|
}
|
|
|
|
if (typeof config.development !== "boolean") {
|
|
|
|
errors++
|
|
|
|
}
|
2021-01-15 18:18:23 +00:00
|
|
|
function getPhoneCodeLocale(): CountryCode {
|
|
|
|
return (process.env.PHONE_COUNTRYCODE as CountryCode);
|
|
|
|
}
|
2020-12-22 11:38:53 +00:00
|
|
|
function getPostalCodeLocale(): any {
|
|
|
|
try {
|
|
|
|
const stringArray: String[] = ValidatorJS.isPostalCodeLocales;
|
|
|
|
let index = stringArray.indexOf(process.env.POSTALCODE_COUNTRYCODE);
|
|
|
|
return ValidatorJS.isPostalCodeLocales[index];
|
|
|
|
} catch (error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2021-01-20 17:28:41 +00:00
|
|
|
function getDataSeeding(): Boolean {
|
|
|
|
try {
|
|
|
|
return JSON.parse(process.env.SEED_TEST_DATA);
|
|
|
|
} catch (error) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-12-09 18:40:08 +00:00
|
|
|
export let e = errors
|