From 892a35acb528e025ddc19385629ac68a8c1d3f57 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Thu, 3 Oct 2024 13:29:40 -0400 Subject: [PATCH] refactor(server): port env (#13158) --- server/src/interfaces/config.interface.ts | 1 + server/src/repositories/config.repository.ts | 1 + server/src/workers/api.ts | 3 +-- server/test/repositories/config.repository.mock.ts | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/server/src/interfaces/config.interface.ts b/server/src/interfaces/config.interface.ts index 9d785e316a..fe0c809bf8 100644 --- a/server/src/interfaces/config.interface.ts +++ b/server/src/interfaces/config.interface.ts @@ -4,6 +4,7 @@ import { VectorExtension } from 'src/interfaces/database.interface'; export const IConfigRepository = 'IConfigRepository'; export interface EnvData { + port: number; environment: ImmichEnvironment; configFile?: string; logLevel?: LogLevel; diff --git a/server/src/repositories/config.repository.ts b/server/src/repositories/config.repository.ts index 0d8e3f76c1..9c65a5608b 100644 --- a/server/src/repositories/config.repository.ts +++ b/server/src/repositories/config.repository.ts @@ -9,6 +9,7 @@ import { EnvData, IConfigRepository } from 'src/interfaces/config.interface'; export class ConfigRepository implements IConfigRepository { getEnv(): EnvData { return { + port: Number(process.env.IMMICH_PORT) || 3001, environment: process.env.IMMICH_ENV as ImmichEnvironment, configFile: process.env.IMMICH_CONFIG_FILE, logLevel: process.env.IMMICH_LOG_LEVEL as LogLevel, diff --git a/server/src/workers/api.ts b/server/src/workers/api.ts index 7e7384f95f..d12d092ea1 100644 --- a/server/src/workers/api.ts +++ b/server/src/workers/api.ts @@ -32,12 +32,11 @@ async function bootstrap() { otelStart(otelPort); - const port = Number(process.env.IMMICH_PORT) || 3001; const app = await NestFactory.create(ApiModule, { bufferLogs: true }); const logger = await app.resolve(ILoggerRepository); const configRepository = app.get(IConfigRepository); - const { environment } = configRepository.getEnv(); + const { environment, port } = configRepository.getEnv(); const isDev = environment === ImmichEnvironment.DEVELOPMENT; logger.setAppName('Api'); diff --git a/server/test/repositories/config.repository.mock.ts b/server/test/repositories/config.repository.mock.ts index e61185225f..41bb8208b9 100644 --- a/server/test/repositories/config.repository.mock.ts +++ b/server/test/repositories/config.repository.mock.ts @@ -4,6 +4,7 @@ import { DatabaseExtension } from 'src/interfaces/database.interface'; import { Mocked, vitest } from 'vitest'; const envData: EnvData = { + port: 3001, environment: ImmichEnvironment.PRODUCTION, database: {