From 4bd9fca8f80b3521c7eff22babb5ff60156dc603 Mon Sep 17 00:00:00 2001 From: Rafael Raposo Date: Fri, 10 May 2024 10:24:45 +0200 Subject: [PATCH] Prefer env port instead hardcoded Signed-off-by: Rafael Raposo --- website/console/env/index.ts | 7 ++++++- website/console/src/server/index.ts | 8 +++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/website/console/env/index.ts b/website/console/env/index.ts index d9a9cd176..4114cb9a8 100644 --- a/website/console/env/index.ts +++ b/website/console/env/index.ts @@ -21,6 +21,9 @@ if (file.error) { /** Current environment environment. "development", "test" or "production" */ const NODE_ENV = process.env.NODE_ENV || 'development'; +/** Port to run the server on */ +const PORT = process.env.PORT || 8080; + /** * Certificate path required for local development, should not include trailing '/'. * Located at top level of the repository in script folder @@ -40,7 +43,7 @@ const ADMIN_API = ADMIN_API_URL ? `//${ADMIN_API_URL}` : ''; const LOCAL_DEV_HOST = process.env.LOCAL_DEV_HOST || `localhost.${ADMIN_API_URL}`; /** - * @depricated use BASE_HREF + * @deprecated use BASE_HREF */ const BASE_URL = process.env.BASE_URL || ''; @@ -76,6 +79,7 @@ const MAINTENANCE_MODE = process.env.MAINTENANCE_MODE || ''; const processEnv = { NODE_ENV, + PORT, ADMIN_API, ADMIN_API_URL, BASE_URL, @@ -86,6 +90,7 @@ const processEnv = { export { NODE_ENV, + PORT, BASE_URL, BASE_HREF, DISABLE_CONSOLE_ROUTE_PREFIX, diff --git a/website/console/src/server/index.ts b/website/console/src/server/index.ts index b2284f4ab..d56f0ea42 100644 --- a/website/console/src/server/index.ts +++ b/website/console/src/server/index.ts @@ -15,8 +15,6 @@ const fs = require('fs'); // const https = require('https'); const env = require('../../env'); -const PORT = 8080; - collectDefaultMetrics(); const app = express(); @@ -56,7 +54,7 @@ app.use(mainRouter); const showEntryPointUrl = () => { console.log(chalk.magenta(`Express server ready!`)); - const url = `https://${env.LOCAL_DEV_HOST}:${PORT}${env.BASE_URL}`; + const url = `https://${env.LOCAL_DEV_HOST}:${env.PORT}${env.BASE_URL}`; // Open a new browser tab if in development if (env.NODE_ENV === 'development') { @@ -84,9 +82,9 @@ if (env.ADMIN_API_USE_SSL === 'https') { }, app, ) - .listen(PORT, showEntryPointUrl); + .listen(env.PORT, showEntryPointUrl); } else { - server = app.listen(PORT, showEntryPointUrl); + server = app.listen(env.PORT, showEntryPointUrl); } const shutdown: NodeJS.SignalsListener = (signal) => {