From 4d851b6e86e4e925a5b6323c9db35c81e2a6c711 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sat, 13 Apr 2024 12:35:21 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Lint=20and=20port=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 4 ++-- services/healthcheck.js | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index e3a9f5d5..76c48f9d 100644 --- a/server.js +++ b/server.js @@ -38,8 +38,8 @@ const ENDPOINTS = require('./src/utils/defaults').serviceEndpoints; // API endpo /* Checks if app is running within a container, from env var */ const isDocker = !!process.env.IS_DOCKER; -/* Checks env var for port. If undefined, will use Port 80 for Docker, or 4000 for metal */ -const port = process.env.PORT || (isDocker ? 80 : 4000); +/* Checks env var for port. If undefined, will use Port 8080 for Docker, or 4000 for metal */ +const port = process.env.PORT || (isDocker ? 8080 : 4000); /* Checks env var for host. If undefined, will use 0.0.0.0 */ const host = process.env.HOST || '0.0.0.0'; diff --git a/services/healthcheck.js b/services/healthcheck.js index d0ba2421..f6eca0cc 100644 --- a/services/healthcheck.js +++ b/services/healthcheck.js @@ -6,11 +6,17 @@ const isSsl = !!process.env.SSL_PRIV_KEY_PATH && !!process.env.SSL_PUB_KEY_PATH; +// eslint-disable-next-line import/no-dynamic-require const http = require(isSsl ? 'https' : 'http'); /* Location of the server to test */ const isDocker = !!process.env.IS_DOCKER; -const port = isSsl ? (process.env.SSL_PORT || (isDocker ? 443 : 4001)) : (process.env.PORT || (isDocker ? 80 : 4000)); + +/* Get the port to use (depending on, if docker, if SSL) */ +const sslPort = process.env.SSL_PORT || (isDocker ? 443 : 4001); +const normalPort = process.env.PORT || (isDocker ? 80 : 4000); +const port = isSsl ? sslPort : normalPort; + const host = process.env.HOST || '0.0.0.0'; const timeout = 2000; @@ -18,7 +24,9 @@ const agent = new http.Agent({ rejectUnauthorized: false, // Allow self-signed certificates }); -const requestOptions = { host, port, timeout, agent }; +const requestOptions = { + host, port, timeout, agent, +}; const startTime = new Date(); // Initialize timestamp to calculate time taken