Skip to content

Commit

Permalink
fix: remove static configuration variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Nomandes authored Dec 22, 2023
1 parent e57bd44 commit 5070297
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/backend/src/index.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
4 changes: 2 additions & 2 deletions packages/backend/src/setupServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -15,7 +15,7 @@ export function setupServer() {
const connectionStore = new ConnectionStore();

const corsOptions: CorsOptions = {
origin: configuration.corsOrigins,
origin: getConfiguration().corsOrigins,
};

const io = new Server<ClientToServerEvents, ServerToClientEvents>(server, {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 } };
};
4 changes: 2 additions & 2 deletions packages/frontend/src/pages/api/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { NextApiRequest, NextApiResponse } from "next";
import { ApplicationConfiguration, configuration } from "@shared/configuration";
import { ApplicationConfiguration, getConfiguration } from "@shared/configuration";

export default function handler(
request: NextApiRequest,
response: NextApiResponse<ApplicationConfiguration>
) {
response.status(200).json(configuration);
response.status(200).json(getConfiguration());
}
1 change: 0 additions & 1 deletion packages/shared/configuration/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/logger/src/logger.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/signaling/src/index.ts
Original file line number Diff line number Diff line change
@@ -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)]);

Expand Down

0 comments on commit 5070297

Please sign in to comment.