Skip to content

Commit

Permalink
fix: Alllow port to be set via env instead hardcoded (#869)
Browse files Browse the repository at this point in the history
Prefer env port instead hardcoded

Signed-off-by: Rafael Raposo <rafaelraposo@spotify.com>
  • Loading branch information
RRap0so committed May 15, 2024
1 parent f80d817 commit bb1db21
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 5 additions & 0 deletions 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 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 bb1db21

Please sign in to comment.