mirror of
https://github.com/docmost/docmost.git
synced 2025-11-13 01:12:37 +10:00
make env validation errors clear
* modify mail smtp variable names
This commit is contained in:
@ -71,28 +71,28 @@ export class EnvironmentService {
|
||||
return this.configService.get<string>('MAIL_DRIVER', 'log');
|
||||
}
|
||||
|
||||
getMailHost(): string {
|
||||
return this.configService.get<string>('MAIL_HOST');
|
||||
}
|
||||
|
||||
getMailPort(): number {
|
||||
return parseInt(this.configService.get<string>('MAIL_PORT'));
|
||||
}
|
||||
|
||||
getMailUsername(): string {
|
||||
return this.configService.get<string>('MAIL_USERNAME');
|
||||
}
|
||||
|
||||
getMailPassword(): string {
|
||||
return this.configService.get<string>('MAIL_PASSWORD');
|
||||
}
|
||||
|
||||
getMailFromAddress(): string {
|
||||
return this.configService.get<string>('MAIL_FROM_ADDRESS');
|
||||
}
|
||||
|
||||
getMailFromName(): string {
|
||||
return this.configService.get<string>('MAIL_FROM_NAME');
|
||||
return this.configService.get<string>('MAIL_FROM_NAME', 'Docmost');
|
||||
}
|
||||
|
||||
getSmtpHost(): string {
|
||||
return this.configService.get<string>('SMTP_HOST');
|
||||
}
|
||||
|
||||
getSmtpPort(): number {
|
||||
return parseInt(this.configService.get<string>('SMTP_PORT'));
|
||||
}
|
||||
|
||||
getSmtpUsername(): string {
|
||||
return this.configService.get<string>('SMTP_USERNAME');
|
||||
}
|
||||
|
||||
getSmtpPassword(): string {
|
||||
return this.configService.get<string>('SMTP_PASSWORD');
|
||||
}
|
||||
|
||||
getPostmarkToken(): string {
|
||||
|
||||
@ -1,12 +1,16 @@
|
||||
import { IsNotEmpty, IsUrl, validateSync } from 'class-validator';
|
||||
import { IsNotEmpty, IsNotIn, IsUrl, validateSync } from 'class-validator';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
|
||||
export class EnvironmentVariables {
|
||||
@IsNotEmpty()
|
||||
@IsUrl({ protocols: ['postgres', 'postgresql'], require_tld: false })
|
||||
@IsUrl(
|
||||
{ protocols: ['postgres', 'postgresql'], require_tld: false },
|
||||
{ message: 'DATABASE_URL must be a valid postgres connection string' },
|
||||
)
|
||||
DATABASE_URL: string;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsNotIn(['REPLACE_WITH_LONG_SECRET'])
|
||||
APP_SECRET: string;
|
||||
}
|
||||
|
||||
@ -14,14 +18,21 @@ export function validate(config: Record<string, any>) {
|
||||
const validatedConfig = plainToInstance(EnvironmentVariables, config);
|
||||
|
||||
const errors = validateSync(validatedConfig);
|
||||
|
||||
console.error(
|
||||
'The EnvironmentVariables has failed the following validations:',
|
||||
);
|
||||
|
||||
if (errors.length > 0) {
|
||||
errors.map((error) => {
|
||||
console.error(error.toString());
|
||||
console.log(JSON.stringify(error.constraints));
|
||||
});
|
||||
|
||||
console.log(
|
||||
'Please fix the environment variables and try again. Shutting down...',
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
return validatedConfig;
|
||||
}
|
||||
|
||||
@ -29,12 +29,12 @@ export const mailDriverConfigProvider = {
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
host: environmentService.getMailHost(),
|
||||
port: environmentService.getMailPort(),
|
||||
host: environmentService.getSmtpHost(),
|
||||
port: environmentService.getSmtpPort(),
|
||||
connectionTimeout: 30 * 1000, // 30 seconds
|
||||
auth: {
|
||||
user: environmentService.getMailUsername(),
|
||||
pass: environmentService.getMailPassword(),
|
||||
user: environmentService.getSmtpUsername(),
|
||||
pass: environmentService.getSmtpPassword(),
|
||||
},
|
||||
} as SMTPTransport.Options,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user