Skip to content

Commit

Permalink
Prefer env port instead hardcoded
Browse files Browse the repository at this point in the history
Signed-off-by: Rafael Raposo <rafaelraposo@spotify.com>
  • Loading branch information
RRap0so committed May 10, 2024
1 parent 364191e commit 4bd9fca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 6 additions & 1 deletion website/console/env/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 || '';

Expand Down Expand Up @@ -76,6 +79,7 @@ const MAINTENANCE_MODE = process.env.MAINTENANCE_MODE || '';

const processEnv = {
NODE_ENV,
PORT,
ADMIN_API,
ADMIN_API_URL,
BASE_URL,
Expand All @@ -86,6 +90,7 @@ const processEnv = {

export {
NODE_ENV,
PORT,
BASE_URL,
BASE_HREF,
DISABLE_CONSOLE_ROUTE_PREFIX,
Expand Down
8 changes: 3 additions & 5 deletions website/console/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const fs = require('fs');
// const https = require('https');
const env = require('../../env');

const PORT = 8080;

collectDefaultMetrics();

const app = express();
Expand Down Expand Up @@ -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') {
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 4bd9fca

Please sign in to comment.