mirror of
https://github.com/docmost/docmost.git
synced 2025-11-12 19:22:39 +10:00
cleanups
This commit is contained in:
@ -9,6 +9,8 @@ import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
import { join } from 'path';
|
||||
import { DatabaseModule } from '@docmost/db/database.module';
|
||||
import * as fs from 'fs';
|
||||
import { StorageModule } from './integrations/storage/storage.module';
|
||||
import { MailModule } from './integrations/mail/mail.module';
|
||||
|
||||
const clientDistPath = join(__dirname, '..', '..', 'client/dist');
|
||||
|
||||
@ -31,6 +33,12 @@ function getServeStaticModule() {
|
||||
CollaborationModule,
|
||||
WsModule,
|
||||
...getServeStaticModule(),
|
||||
StorageModule.forRootAsync({
|
||||
imports: [EnvironmentModule],
|
||||
}),
|
||||
MailModule.forRootAsync({
|
||||
imports: [EnvironmentModule],
|
||||
}),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
||||
@ -8,16 +8,13 @@ import { UserModule } from './user/user.module';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { WorkspaceModule } from './workspace/workspace.module';
|
||||
import { PageModule } from './page/page.module';
|
||||
import { StorageModule } from '../integrations/storage/storage.module';
|
||||
import { AttachmentModule } from './attachment/attachment.module';
|
||||
import { EnvironmentModule } from '../integrations/environment/environment.module';
|
||||
import { CommentModule } from './comment/comment.module';
|
||||
import { SearchModule } from './search/search.module';
|
||||
import { SpaceModule } from './space/space.module';
|
||||
import { GroupModule } from './group/group.module';
|
||||
import { CaslModule } from './casl/casl.module';
|
||||
import { DomainMiddleware } from '../middlewares/domain.middleware';
|
||||
import { MailModule } from '../integrations/mail/mail.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@ -25,12 +22,6 @@ import { MailModule } from '../integrations/mail/mail.module';
|
||||
AuthModule,
|
||||
WorkspaceModule,
|
||||
PageModule,
|
||||
StorageModule.forRootAsync({
|
||||
imports: [EnvironmentModule],
|
||||
}),
|
||||
MailModule.forRootAsync({
|
||||
imports: [EnvironmentModule],
|
||||
}),
|
||||
AttachmentModule,
|
||||
CommentModule,
|
||||
SearchModule,
|
||||
|
||||
1
apps/server/src/helpers/index.ts
Normal file
1
apps/server/src/helpers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './utils';
|
||||
@ -2,7 +2,7 @@ import { Global, Module } from '@nestjs/common';
|
||||
import { EnvironmentService } from './environment.service';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { validate } from './environment.validation';
|
||||
import { envPath } from '../../helpers/utils';
|
||||
import { envPath } from '../../helpers';
|
||||
|
||||
@Global()
|
||||
@Module({
|
||||
|
||||
@ -9,8 +9,8 @@ export class EnvironmentService {
|
||||
return this.configService.get<string>('NODE_ENV');
|
||||
}
|
||||
|
||||
getPort(): string {
|
||||
return this.configService.get<string>('PORT');
|
||||
getPort(): number {
|
||||
return parseInt(this.configService.get<string>('PORT'));
|
||||
}
|
||||
getDatabaseURL(): string {
|
||||
return this.configService.get<string>('DATABASE_URL');
|
||||
@ -80,7 +80,7 @@ export class EnvironmentService {
|
||||
}
|
||||
|
||||
getMailPort(): number {
|
||||
return this.configService.get<number>('MAIL_PORT');
|
||||
return parseInt(this.configService.get<string>('MAIL_PORT'));
|
||||
}
|
||||
|
||||
getMailUsername(): string {
|
||||
|
||||
@ -24,37 +24,36 @@ export const mailDriverConfigProvider = {
|
||||
useFactory: async (environmentService: EnvironmentService) => {
|
||||
const driver = environmentService.getMailDriver().toLocaleLowerCase();
|
||||
|
||||
if (driver === MailOption.SMTP) {
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
host: environmentService.getMailHost(),
|
||||
port: environmentService.getMailPort(),
|
||||
connectionTimeout: 30 * 1000, // 30 seconds
|
||||
auth: {
|
||||
user: environmentService.getMailUsername(),
|
||||
pass: environmentService.getMailPassword(),
|
||||
},
|
||||
} as SMTPTransport.Options,
|
||||
};
|
||||
}
|
||||
switch (driver) {
|
||||
case MailOption.SMTP:
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
host: environmentService.getMailHost(),
|
||||
port: environmentService.getMailPort(),
|
||||
connectionTimeout: 30 * 1000, // 30 seconds
|
||||
auth: {
|
||||
user: environmentService.getMailUsername(),
|
||||
pass: environmentService.getMailPassword(),
|
||||
},
|
||||
} as SMTPTransport.Options,
|
||||
};
|
||||
|
||||
if (driver === MailOption.Postmark) {
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
postmarkToken: environmentService.getPostmarkToken(),
|
||||
} as PostmarkConfig,
|
||||
};
|
||||
}
|
||||
case MailOption.Postmark:
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
postmarkToken: environmentService.getPostmarkToken(),
|
||||
} as PostmarkConfig,
|
||||
};
|
||||
|
||||
if (driver === MailOption.Log) {
|
||||
return {
|
||||
driver,
|
||||
};
|
||||
case MailOption.Log:
|
||||
return {
|
||||
driver,
|
||||
};
|
||||
default:
|
||||
throw new Error(`Unknown mail driver: ${driver}`);
|
||||
}
|
||||
|
||||
throw new Error(`Unknown mail driver: ${driver}`);
|
||||
},
|
||||
|
||||
inject: [EnvironmentService],
|
||||
|
||||
@ -26,34 +26,35 @@ function createStorageDriver(disk: StorageConfig): StorageDriver {
|
||||
export const storageDriverConfigProvider = {
|
||||
provide: STORAGE_CONFIG_TOKEN,
|
||||
useFactory: async (environmentService: EnvironmentService) => {
|
||||
const driver = environmentService.getStorageDriver();
|
||||
const driver = environmentService.getStorageDriver().toLowerCase();
|
||||
|
||||
if (driver === StorageOption.LOCAL) {
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
storagePath:
|
||||
process.cwd() + '/' + environmentService.getLocalStoragePath(),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (driver === StorageOption.S3) {
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
region: environmentService.getAwsS3Region(),
|
||||
endpoint: environmentService.getAwsS3Endpoint(),
|
||||
bucket: environmentService.getAwsS3Bucket(),
|
||||
credentials: {
|
||||
accessKeyId: environmentService.getAwsS3AccessKeyId(),
|
||||
secretAccessKey: environmentService.getAwsS3SecretAccessKey(),
|
||||
switch (driver) {
|
||||
case StorageOption.LOCAL:
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
storagePath:
|
||||
process.cwd() + '/' + environmentService.getLocalStoragePath(),
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
throw new Error(`Unknown storage driver: ${driver}`);
|
||||
case StorageOption.S3:
|
||||
return {
|
||||
driver,
|
||||
config: {
|
||||
region: environmentService.getAwsS3Region(),
|
||||
endpoint: environmentService.getAwsS3Endpoint(),
|
||||
bucket: environmentService.getAwsS3Bucket(),
|
||||
credentials: {
|
||||
accessKeyId: environmentService.getAwsS3AccessKeyId(),
|
||||
secretAccessKey: environmentService.getAwsS3SecretAccessKey(),
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
default:
|
||||
throw new Error(`Unknown storage driver: ${driver}`);
|
||||
}
|
||||
},
|
||||
|
||||
inject: [EnvironmentService],
|
||||
@ -61,6 +62,6 @@ export const storageDriverConfigProvider = {
|
||||
|
||||
export const storageDriverProvider = {
|
||||
provide: STORAGE_DRIVER_TOKEN,
|
||||
useFactory: (config) => createStorageDriver(config),
|
||||
useFactory: (config: StorageConfig) => createStorageDriver(config),
|
||||
inject: [STORAGE_CONFIG_TOKEN],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user