Skip to content

Commit

Permalink
refactor: rename server configuration variables for clarity and consi…
Browse files Browse the repository at this point in the history
…stency
  • Loading branch information
SevenWaysDP committed Nov 29, 2024
1 parent 7dfd2e8 commit 39b8d8d
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions .env.default
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ S3_PORT=9000
S3_SECRET_KEY=miniouser
S3_SSL=false

SERVER_FEATURE_TLDRAW_ENABLED=true
SERVER_WEBSOCKET_URL=ws://localhost:3345
FEATURE_TLDRAW_ENABLED=true
TLDRAW_WEBSOCKET_URL=ws://localhost:3345

X_API_ALLOWED_KEYS=randomString
4 changes: 2 additions & 2 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ S3_PORT=9000
S3_SECRET_KEY=miniouser
S3_SSL=false

SERVER_FEATURE_TLDRAW_ENABLED=true
SERVER_WEBSOCKET_URL=ws://localhost:3345
FEATURE_TLDRAW_ENABLED=true
TLDRAW_WEBSOCKET_URL=ws://localhost:3345

X_API_ALLOWED_KEYS=randomString
2 changes: 1 addition & 1 deletion ansible/roles/tldraw-server/defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST : "image/png,image/jpeg,image/gif,image/svg+xml"
TLDRAW_LOG_LEVEL: "error"
TLDRAW_METRICS_COLLECT_DEFAULT: "true"
TLDRAW_SERVER_ASSETS_ENABLED: "true"
TLDRAW_ASSETS_ENABLED: "true"
TLDRAW_WEBSOCKET_PATH: "/tldraw-server"
10 changes: 5 additions & 5 deletions ansible/roles/tldraw-server/templates/configmap.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ data:
METRICS_COLLECT_DEFAULT: "{{ TLDRAW_METRICS_COLLECT_DEFAULT }}"
REDIS_CLUSTER_ENABLED: "true"
REDIS_SENTINEL_SERVICE_NAME: "valkey-headless.{{ NAMESPACE }}.svc.cluster.local"
SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST: "{{ TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST }}"
SERVER_ASSETS_ENABLED: "{{ TLDRAW_SERVER_ASSETS_ENABLED }}"
SERVER_FEATURE_TLDRAW_ENABLED: "{{ FEATURE_TLDRAW_ENABLED }}"
SERVER_WEBSOCKET_PATH: "{{ TLDRAW_WEBSOCKET_PATH }}"
SERVER_WEBSOCKET_URL: "wss://{{ DOMAIN }}{{ TLDRAW_WEBSOCKET_PATH }}"
TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST: "{{ TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST }}"
TLDRAW_ASSETS_ENABLED: "{{ TLDRAW_ASSETS_ENABLED }}"
FEATURE_TLDRAW_ENABLED: "{{ FEATURE_TLDRAW_ENABLED }}"
TLDRAW_WEBSOCKET_PATH: "{{ TLDRAW_WEBSOCKET_PATH }}"
TLDRAW_WEBSOCKET_URL: "wss://{{ DOMAIN }}{{ TLDRAW_WEBSOCKET_PATH }}"
14 changes: 7 additions & 7 deletions src/modules/server/api/dto/tldraw-config.response.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ApiProperty } from '@nestjs/swagger';
import { ServerConfig } from '../../server.config.js';
import { TldrawServerConfig } from '../../tldraw-server.config.js';

export class TldrawPublicConfigResponse {
public constructor(config: ServerConfig) {
this.TLDRAW_WEBSOCKET_URL = config.SERVER_WEBSOCKET_URL;
this.TLDRAW_ASSETS_ENABLED = config.SERVER_ASSETS_ENABLED;
this.TLDRAW_ASSETS_MAX_SIZE_BYTES = config.SERVER_ASSETS_MAX_SIZE_BYTES;
this.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST = config.SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST;
this.FEATURE_TLDRAW_ENABLED = config.SERVER_FEATURE_TLDRAW_ENABLED;
public constructor(config: TldrawServerConfig) {
this.TLDRAW_WEBSOCKET_URL = config.TLDRAW_WEBSOCKET_URL;
this.TLDRAW_ASSETS_ENABLED = config.TLDRAW_ASSETS_ENABLED;
this.TLDRAW_ASSETS_MAX_SIZE_BYTES = config.TLDRAW_ASSETS_MAX_SIZE_BYTES;
this.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST = config.TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST;
this.FEATURE_TLDRAW_ENABLED = config.FEATURE_TLDRAW_ENABLED;
}

@ApiProperty()
Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/api/tldraw-confg.controller.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
import { ServerConfig } from '../server.config.js';
import { TldrawServerConfig } from '../tldraw-server.config.js';
import { TldrawPublicConfigResponse } from './dto/tldraw-config.response.js';

@ApiTags('tldraw/config')
@Controller('tldraw/config')
export class TldrawConfigController {
public constructor(private readonly config: ServerConfig) {}
public constructor(private readonly config: TldrawServerConfig) {}

@ApiOperation({ summary: 'Useable configuration for clients' })
@ApiResponse({ status: 200, type: TldrawPublicConfigResponse })
Expand Down
8 changes: 4 additions & 4 deletions src/modules/server/api/websocket.gateway.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { RedisService } from '../../../infra/redis/redis.service.js';
import { StorageService } from '../../../infra/storage/storage.service.js';
import * as WsService from '../../../infra/y-redis/ws.service.js';
import { registerYWebsocketServer } from '../../../infra/y-redis/ws.service.js';
import { ServerConfig } from '../server.config.js';
import { TldrawServerConfig } from '../tldraw-server.config.js';
import { WebsocketGateway } from './websocket.gateway.js';

describe(WebsocketGateway.name, () => {
Expand Down Expand Up @@ -44,10 +44,10 @@ describe(WebsocketGateway.name, () => {
useValue: createMock<Logger>(),
},
{
provide: ServerConfig,
provide: TldrawServerConfig,
useValue: {
SERVER_WEBSOCKET_PATH: 'tests',
SERVER_WEBSOCKET_PORT: 3345,
TLDRAW_WEBSOCKET_PATH: 'tests',
TLDRAW_WEBSOCKET_PORT: 3345,
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions src/modules/server/api/websocket.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { MetricsService } from '../../../infra/metrics/metrics.service.js';
import { RedisService } from '../../../infra/redis/redis.service.js';
import { StorageService } from '../../../infra/storage/storage.service.js';
import { registerYWebsocketServer } from '../../../infra/y-redis/ws.service.js';
import { ServerConfig } from '../server.config.js';
import { TldrawServerConfig } from '../tldraw-server.config.js';

export const UWS = 'UWS';

Expand All @@ -17,7 +17,7 @@ export class WebsocketGateway implements OnModuleInit, OnModuleDestroy {
private readonly storageService: StorageService,
private readonly authorizationService: AuthorizationService,
private readonly redisService: RedisService,
private readonly config: ServerConfig,
private readonly config: TldrawServerConfig,
private readonly logger: Logger,
) {
this.logger.setContext(WebsocketGateway.name);
Expand All @@ -28,8 +28,8 @@ export class WebsocketGateway implements OnModuleInit, OnModuleDestroy {
}

public async onModuleInit(): Promise<void> {
const wsPathPrefix = this.config.SERVER_WEBSOCKET_PATH;
const wsPort = this.config.SERVER_WEBSOCKET_PORT;
const wsPathPrefix = this.config.TLDRAW_WEBSOCKET_PATH;
const wsPort = this.config.TLDRAW_WEBSOCKET_PORT;

await registerYWebsocketServer(
this.webSocketServer,
Expand Down
4 changes: 2 additions & 2 deletions src/modules/server/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { StorageModule } from '../../infra/storage/storage.module.js';
import { TldrawConfigController } from './api/tldraw-confg.controller.js';
import { TldrawDocumentController } from './api/tldraw-document.controller.js';
import { UWS, WebsocketGateway } from './api/websocket.gateway.js';
import { ServerConfig } from './server.config.js';
import { TldrawDocumentService } from './service/tldraw-document.service.js';
import { TldrawServerConfig } from './tldraw-server.config.js';

@Module({
imports: [
ConfigurationModule.register(ServerConfig),
ConfigurationModule.register(TldrawServerConfig),
RedisModule,
StorageModule,
AuthorizationModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { Transform } from 'class-transformer';
import { IsArray, IsBoolean, IsNumber, IsString, IsUrl } from 'class-validator';

export class ServerConfig {
export class TldrawServerConfig {
@IsString()
public SERVER_WEBSOCKET_PATH = '';
public TLDRAW_WEBSOCKET_PATH = '';

@IsNumber()
@Transform(({ value }) => parseInt(value))
public SERVER_WEBSOCKET_PORT = 3345;
public TLDRAW_WEBSOCKET_PORT = 3345;

@IsUrl({ protocols: ['wss', 'ws'], require_tld: false })
public SERVER_WEBSOCKET_URL!: string;
public TLDRAW_WEBSOCKET_URL!: string;

@Transform(({ value }) => value === 'true')
@IsBoolean()
public SERVER_ASSETS_ENABLED = true;
public TLDRAW_ASSETS_ENABLED = true;

@Transform(({ value }) => parseInt(value))
@IsNumber()
public SERVER_ASSETS_MAX_SIZE_BYTES = 10485760;
public TLDRAW_ASSETS_MAX_SIZE_BYTES = 10485760;

@Transform(({ value }) => value.split(','))
@IsArray()
public SERVER_ASSETS_ALLOWED_MIME_TYPES_LIST = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];
public TLDRAW_ASSETS_ALLOWED_MIME_TYPES_LIST = ['image/png', 'image/jpeg', 'image/gif', 'image/svg+xml'];

@Transform(({ value }) => value === 'true')
@IsBoolean()
public SERVER_FEATURE_TLDRAW_ENABLED!: boolean;
public FEATURE_TLDRAW_ENABLED!: boolean;
}

0 comments on commit 39b8d8d

Please sign in to comment.