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",
|
2021-03-06 12:41:10 +00:00
|
|
|
testing: process.env.NODE_ENV === "test",
|
2020-12-09 18:42:51 +00:00
|
|
|
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-02-07 12:37:01 +00:00
|
|
|
app_url: process.env.APP_URL || "http://localhost:8080",
|
2021-02-02 14:04:09 +00:00
|
|
|
privacy_url: process.env.PRIVACY_URL || "/privacy",
|
2021-03-04 15:11:05 +00:00
|
|
|
imprint_url: process.env.IMPRINT_URL || "/imprint",
|
2021-03-04 15:19:19 +00:00
|
|
|
mailer_url: process.env.MAILER_URL || "",
|
|
|
|
mailer_key: process.env.MAILER_KEY || ""
|
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-03-04 15:19:19 +00:00
|
|
|
if (config.mailer_url == "" || config.mailer_key == "") {
|
|
|
|
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
|