Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
json,
port,
num,
str,
url,
type ValidatorSpec
} from 'envalid'
const booleanValidatorSpec: ValidatorSpec = bool()
const numberValidatorSpec: ValidatorSpec = num()
const stringValidatorSpec: ValidatorSpec = str()
const jsonValidatorSpec: ValidatorSpec = json()
const urlValidatorSpec: ValidatorSpec = url()
const emailValidatorSpec: ValidatorSpec = email()
const hostValidatorSpec: ValidatorSpec = host()
const portValidatorSpec: ValidatorSpec = port()
const env1: { NODE_ENV: string, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
// $ExpectError
const env2: { NODE_ENV: number, ... } = cleanEnv({ NODE_ENV: 'TEST' }, {
NODE_ENV: str()
})
// $ExpectError
const invalidBooleanValidatorSpec: ValidatorSpec = bool()
private validate(dotEnvPath: string): IDotEnv {
const rule = {
PROTOCOL: envalid.str({ choices: ['http', 'https'], default: 'http' }),
PORT: envalid.port({ default: 5555 }),
//
DEMO_MODE: envalid.str({ choices: ['true', 'false'], default: 'false' }),
DEBUG_MODE: envalid.str({ choices: ['true', 'false'], default: 'false' }),
//
BASE_HOST: envalid.str(),
PUBLIC_DIR: envalid.str(),
ATTACHMENT_DIR: envalid.str(),
ATTACHMENT_LIMIT_SIZE_MB: envalid.num(),
ATTACHMENT_SAVE_IN_LOCAL: envalid.str({ choices: ['true', 'false'], default: 'false' }),
ATTACHMENT_SAVE_IN_OSS: envalid.str({ choices: ['true', 'false'], default: 'false' }),
//
DB_TYPE: envalid.str({ choices: ['mysql'], default: 'mysql' }),
DB_HOST: envalid.str(),
DB_PORT: envalid.num(),
DB_USER: envalid.str(),
DB_PASSWORD: envalid.str(),
function validateEnv() {
cleanEnv(process.env, {
JWT_SECRET: str(),
OPEN_CAGE_DATA_KEY: str(),
PORT: port(),
POSTGRES_DB: str(),
POSTGRES_HOST: str(),
POSTGRES_PASSWORD: str(),
POSTGRES_PORT: port(),
POSTGRES_USER: str(),
REDIS_URL: str(),
});
}
function validateEnv() {
cleanEnv(process.env, {
JWT_SECRET: str(),
OPEN_CAGE_DATA_KEY: str(),
PORT: port(),
POSTGRES_DB: str(),
POSTGRES_HOST: str(),
POSTGRES_PASSWORD: str(),
POSTGRES_PORT: port(),
POSTGRES_USER: str(),
REDIS_URL: str(),
});
}
function validateEnv() {
cleanEnv(process.env, {
JWT_SECRET: str(),
MONGO_PASSWORD: str(),
MONGO_PATH: str(),
MONGO_USER: str(),
PORT: port(),
});
}
const validateEnv = () => {
cleanEnv(process.env, {
API_BASE_URL: url(),
CLIENT_REDIRECT_URL: url(),
EMAIL_FROM_DEFAULT: str(),
EMAIL_TO_DEFAULT: str(),
JWT_SECRET: str(),
OPEN_CAGE_DATA_KEY: str(),
PORT: port(),
POSTGRES_DB: str(),
POSTGRES_HOST: str(),
POSTGRES_PASSWORD: str(),
POSTGRES_PORT: port(),
POSTGRES_USER: str(),
REDIS_URL: str(),
SENDGRID_API_KEY: str(),
});
};
const validateEnv = () => {
cleanEnv(process.env, {
API_BASE_URL: url(),
CLIENT_REDIRECT_URL: url(),
EMAIL_FROM_DEFAULT: str(),
EMAIL_TO_DEFAULT: str(),
JWT_SECRET: str(),
OPEN_CAGE_DATA_KEY: str(),
PORT: port(),
POSTGRES_DB: str(),
POSTGRES_HOST: str(),
POSTGRES_PASSWORD: str(),
POSTGRES_PORT: port(),
POSTGRES_USER: str(),
REDIS_URL: str(),
SENDGRID_API_KEY: str(),
});
};