mirror of
https://github.com/docmost/docmost.git
synced 2025-11-10 07:02:06 +10:00
more env validations
This commit is contained in:
@ -19,7 +19,6 @@ AWS_S3_SECRET_ACCESS_KEY=
|
||||
AWS_S3_REGION=
|
||||
AWS_S3_BUCKET=
|
||||
AWS_S3_ENDPOINT=
|
||||
AWS_S3_URL=
|
||||
|
||||
# options: smtp | postmark
|
||||
MAIL_DRIVER=smtp
|
||||
|
||||
@ -1,4 +1,11 @@
|
||||
import { IsNotEmpty, IsNotIn, IsUrl, validateSync } from 'class-validator';
|
||||
import {
|
||||
IsIn,
|
||||
IsNotEmpty,
|
||||
IsNotIn,
|
||||
IsOptional,
|
||||
IsUrl,
|
||||
validateSync,
|
||||
} from 'class-validator';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
|
||||
export class EnvironmentVariables {
|
||||
@ -9,9 +16,28 @@ export class EnvironmentVariables {
|
||||
)
|
||||
DATABASE_URL: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsUrl(
|
||||
{ protocols: ['redis', 'rediss'], require_tld: false },
|
||||
{ message: 'REDIS_URL must be a valid redis connection string' },
|
||||
)
|
||||
REDIS_URL: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
|
||||
APP_URL: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNotIn(['REPLACE_WITH_LONG_SECRET'])
|
||||
APP_SECRET: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['smtp', 'postmark'])
|
||||
MAIL_DRIVER: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsIn(['local', 's3'])
|
||||
STORAGE_DRIVER: string;
|
||||
}
|
||||
|
||||
export function validate(config: Record<string, any>) {
|
||||
@ -19,17 +45,17 @@ export function validate(config: Record<string, any>) {
|
||||
|
||||
const errors = validateSync(validatedConfig);
|
||||
|
||||
console.error(
|
||||
'The EnvironmentVariables has failed the following validations:',
|
||||
);
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error(
|
||||
'The Environment variables has failed the following validations:',
|
||||
);
|
||||
|
||||
errors.map((error) => {
|
||||
console.log(JSON.stringify(error.constraints));
|
||||
console.error(JSON.stringify(error.constraints));
|
||||
});
|
||||
|
||||
console.log(
|
||||
'Please fix the environment variables and try again. Shutting down...',
|
||||
console.error(
|
||||
'Please fix the environment variables and try again. Exiting program...',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user