From e735363cfe8d6b9d60ba1fc115e4c6f80c12a69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Lehe=CC=81?= Date: Thu, 21 Dec 2023 14:49:21 +0100 Subject: [PATCH] fix: remove static config variable --- packages/backend/src/index.ts | 4 ++-- packages/backend/src/setupServer.ts | 4 ++-- .../frontend/src/common/utils/globalGetServerSideProps.ts | 4 ++-- packages/shared/configuration/src/configuration.ts | 1 - packages/shared/logger/src/logger.ts | 4 ++-- packages/signaling/src/index.ts | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/packages/backend/src/index.ts b/packages/backend/src/index.ts index ffebcad5..64f25e28 100644 --- a/packages/backend/src/index.ts +++ b/packages/backend/src/index.ts @@ -1,11 +1,11 @@ import { setupServer } from "./setupServer"; import { logger } from "@shared/logger"; import dotenv from "dotenv"; -import { configuration } from "@shared/configuration"; +import { getConfiguration } from "@shared/configuration"; dotenv.config(); -const serverPort = configuration.backendUrl.port; +const serverPort = getConfiguration().backendUrl.port; const server = setupServer(); diff --git a/packages/backend/src/setupServer.ts b/packages/backend/src/setupServer.ts index aa91a750..f53f74ea 100644 --- a/packages/backend/src/setupServer.ts +++ b/packages/backend/src/setupServer.ts @@ -6,7 +6,7 @@ import cors, { CorsOptions } from "cors"; import { ClientToServerEvents, ServerToClientEvents } from "@shared/socket"; import { ConnectionStore } from "./store/ConnectionStore"; import { logger } from "@shared/logger"; -import { configuration } from "@shared/configuration"; +import { getConfiguration } from "@shared/configuration"; export function setupServer() { const app = express(); @@ -15,7 +15,7 @@ export function setupServer() { const connectionStore = new ConnectionStore(); const corsOptions: CorsOptions = { - origin: configuration.corsOrigins, + origin: getConfiguration().corsOrigins, }; const io = new Server(server, { diff --git a/packages/frontend/src/common/utils/globalGetServerSideProps.ts b/packages/frontend/src/common/utils/globalGetServerSideProps.ts index eef0407c..61c70166 100644 --- a/packages/frontend/src/common/utils/globalGetServerSideProps.ts +++ b/packages/frontend/src/common/utils/globalGetServerSideProps.ts @@ -1,5 +1,5 @@ import { GetServerSideProps } from "next"; -import { ApplicationConfiguration, configuration } from "@shared/configuration"; +import { ApplicationConfiguration, getConfiguration } from "@shared/configuration"; export interface GlobalGetServerSideProps { configuration: ApplicationConfiguration; @@ -8,6 +8,6 @@ export interface GlobalGetServerSideProps { export const globalGetServerSideProps: GetServerSideProps<{ configuration: ApplicationConfiguration; }> = async () => { - const parsedConfiguration = JSON.parse(JSON.stringify(configuration)); + const parsedConfiguration = JSON.parse(JSON.stringify(getConfiguration())); return { props: { configuration: parsedConfiguration } }; }; diff --git a/packages/shared/configuration/src/configuration.ts b/packages/shared/configuration/src/configuration.ts index 8a4e65cc..37b45cb9 100644 --- a/packages/shared/configuration/src/configuration.ts +++ b/packages/shared/configuration/src/configuration.ts @@ -1,6 +1,5 @@ import { ApplicationConfiguration, CorsOrigins, IceServerConfiguration, LogLevel } from "./types"; import { RetroAppUrl } from "./RetroAppUrl"; -export const configuration = getConfiguration(); export function getConfiguration(): ApplicationConfiguration { const backendUrl = new RetroAppUrl({ diff --git a/packages/shared/logger/src/logger.ts b/packages/shared/logger/src/logger.ts index de7c7f6a..8d8c9190 100644 --- a/packages/shared/logger/src/logger.ts +++ b/packages/shared/logger/src/logger.ts @@ -1,5 +1,5 @@ import { createLogger as createWinstonLogger, format, transports } from "winston"; -import { configuration } from "@shared/configuration"; +import { getConfiguration } from "@shared/configuration"; const loggerFormat = format.combine( format.timestamp({ @@ -11,7 +11,7 @@ const loggerFormat = format.combine( ); export const logger = createLogger({ - logLevel: configuration.logLevel, + logLevel: getConfiguration().logLevel, }); export function createLogger({ withConsolePipe = true, logLevel }: CreateLoggerOptions) { diff --git a/packages/signaling/src/index.ts b/packages/signaling/src/index.ts index fb2ea7e9..ef6ba0dc 100644 --- a/packages/signaling/src/index.ts +++ b/packages/signaling/src/index.ts @@ -1,11 +1,11 @@ import dotenv from "dotenv"; -import { configuration } from "@shared/configuration"; +import { getConfiguration } from "@shared/configuration"; import { spawn } from "child_process"; import { logger } from "@shared/logger"; dotenv.config(); -const signalingServerPort = configuration.signalingServerUrl.port; +const signalingServerPort = getConfiguration().signalingServerUrl.port; const peerServer = spawn("peerjs", ["--port", String(signalingServerPort)]);