Skip to content

Commit

Permalink
Add validation to ensure a valid port is set
Browse files Browse the repository at this point in the history
  • Loading branch information
antonym committed Feb 5, 2024
1 parent 1be9df6 commit 58e15d7
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,19 @@ async function downloader(downloads){
io.emit('purgestatus');
}

// Spin up application on port 3000 or set to WEB_APP_PORT env variable
app.use(baseurl, baserouter);
const port = process.env.WEB_APP_PORT || 3000;

// Spin up application on port 3000 or set to WEB_APP_PORT env variable

const defaultPort = 3000;

let port = process.env.WEB_APP_PORT;

if (!Number.isInteger(Number(port)) || port < 1 || port > 65535) {
console.warn(`Invalid port "${port}" in environment variable WEB_APP_PORT. Using default port ${defaultPort} instead.`);
port = defaultPort;
}

http.listen(port, function(){
console.log('listening on *:' + port);
});

0 comments on commit 58e15d7

Please sign in to comment.