* integrate websocket redis adapter
* use APP_SECRET for jwt signing
* auto migrate database on startup in production
* add updatedAt to update db operations
* create enterprise ee package directory
* fix comment editor focus
* other fixes
This commit is contained in:
Philipinho
2024-06-07 17:29:34 +01:00
parent eef9081aaf
commit 38ef610e5e
36 changed files with 541 additions and 166 deletions

View File

@ -5,8 +5,8 @@ import { ConfigService } from '@nestjs/config';
export class EnvironmentService {
constructor(private configService: ConfigService) {}
getEnv(): string {
return this.configService.get<string>('NODE_ENV');
getNodeEnv(): string {
return this.configService.get<string>('NODE_ENV', 'development');
}
getAppUrl(): string {
@ -17,7 +17,7 @@ export class EnvironmentService {
}
getPort(): number {
return parseInt(this.configService.get<string>('PORT'));
return parseInt(this.configService.get<string>('PORT', '3000'));
}
getAppSecret(): string {
@ -28,20 +28,19 @@ export class EnvironmentService {
return this.configService.get<string>('DATABASE_URL');
}
getJwtSecret(): string {
return this.configService.get<string>('JWT_SECRET_KEY');
getRedisUrl(): string {
return this.configService.get<string>(
'REDIS_URL',
'redis://localhost:6379',
);
}
getJwtTokenExpiresIn(): string {
return this.configService.get<string>('JWT_TOKEN_EXPIRES_IN');
return this.configService.get<string>('JWT_TOKEN_EXPIRES_IN', '30d');
}
getStorageDriver(): string {
return this.configService.get<string>('STORAGE_DRIVER');
}
getLocalStoragePath(): string {
return this.configService.get<string>('LOCAL_STORAGE_PATH');
return this.configService.get<string>('STORAGE_DRIVER', 'local');
}
getAwsS3AccessKeyId(): string {
@ -68,27 +67,12 @@ export class EnvironmentService {
return this.configService.get<string>('AWS_S3_URL');
}
getAwsS3UsePathStyleEndpoint(): boolean {
return this.configService.get<boolean>('AWS_S3_USE_PATH_STYLE_ENDPOINT');
}
isCloud(): boolean {
const cloudConfig = this.configService
.get<string>('CLOUD', 'false')
.toLowerCase();
return cloudConfig === 'true';
}
isSelfHosted(): boolean {
return !this.isCloud();
}
getMailDriver(): string {
return this.configService.get<string>('MAIL_DRIVER', 'log');
}
getMailHost(): string {
return this.configService.get<string>('MAIL_HOST', '127.0.0.1');
return this.configService.get<string>('MAIL_HOST');
}
getMailPort(): number {
@ -115,10 +99,14 @@ export class EnvironmentService {
return this.configService.get<string>('POSTMARK_TOKEN');
}
getRedisUrl(): string {
return this.configService.get<string>(
'REDIS_URL',
'redis://@127.0.0.1:6379',
);
isCloud(): boolean {
const cloudConfig = this.configService
.get<string>('CLOUD', 'false')
.toLowerCase();
return cloudConfig === 'true';
}
isSelfHosted(): boolean {
return !this.isCloud();
}
}

View File

@ -1,14 +1,12 @@
import { IsString, IsUrl, validateSync } from 'class-validator';
import { IsNotEmpty, IsUrl, validateSync } from 'class-validator';
import { plainToInstance } from 'class-transformer';
export class EnvironmentVariables {
@IsString()
NODE_ENV: string;
@IsNotEmpty()
@IsUrl({ protocols: ['postgres', 'postgresql'], require_tld: false })
DATABASE_URL: string;
@IsString()
@IsNotEmpty()
APP_SECRET: string;
}

View File

@ -0,0 +1,19 @@
import { ConsoleLogger } from '@nestjs/common';
export class InternalLogFilter extends ConsoleLogger {
static contextsToIgnore = [
'InstanceLoader',
'RoutesResolver',
'RouterExplorer',
'WebSocketsController',
];
log(_: any, context?: string): void {
if (
process.env.NODE_ENV !== 'production' ||
!InternalLogFilter.contextsToIgnore.includes(context)
) {
super.log.apply(this, arguments);
}
}
}

View File

@ -1,7 +1,7 @@
import { Global, Module } from '@nestjs/common';
import { BullModule } from '@nestjs/bullmq';
import { EnvironmentService } from '../environment/environment.service';
import { parseRedisUrl } from '../../helpers';
import { createRetryStrategy, parseRedisUrl } from '../../helpers';
import { QueueName } from './constants';
@Global()
@ -15,9 +15,7 @@ import { QueueName } from './constants';
host: redisConfig.host,
port: redisConfig.port,
password: redisConfig.password,
retryStrategy: function (times: number) {
return Math.max(Math.min(Math.exp(times), 20000), 1000);
},
retryStrategy: createRetryStrategy(),
},
defaultJobOptions: {
attempts: 3,

View File

@ -30,7 +30,7 @@ export class StaticModule implements OnModuleInit {
const windowVar = '<!--window-config-->';
const configString = {
ENV: this.environmentService.getEnv(),
ENV: this.environmentService.getNodeEnv(),
APP_URL: this.environmentService.getAppUrl(),
IS_CLOUD: this.environmentService.isCloud(),
};

View File

@ -11,6 +11,8 @@ import {
StorageOption,
} from '../interfaces';
import { LocalDriver, S3Driver } from '../drivers';
import * as process from 'node:process';
import { LOCAL_STORAGE_PATH } from '../../../helpers';
function createStorageDriver(disk: StorageConfig): StorageDriver {
switch (disk.driver) {
@ -33,8 +35,7 @@ export const storageDriverConfigProvider = {
return {
driver,
config: {
storagePath:
process.cwd() + '/' + environmentService.getLocalStoragePath(),
storagePath: process.cwd() + '/' + LOCAL_STORAGE_PATH,
},
};