From d05152930663db4169ac3e73fb57e26a177a8fa2 Mon Sep 17 00:00:00 2001 From: Artur Owczarek Date: Mon, 28 Oct 2024 12:46:03 +0100 Subject: [PATCH] feature: Better handling of missing environment variables in setupProxy.js file. Signed-off-by: Artur Owczarek --- web/setupProxy.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/web/setupProxy.js b/web/setupProxy.js index ecd677b607..d8db40b2ba 100644 --- a/web/setupProxy.js +++ b/web/setupProxy.js @@ -3,13 +3,23 @@ const { createProxyMiddleware } = require('http-proxy-middleware'); const express = require('express') const router = express.Router() +const environmentVariable = (variableName) => { + const value = process.env[variableName] + if (!value) { + console.error(`Error: ${variableName} environment variable is not defined.`) + console.error(`Please set ${variableName} and restart the application.`) + process.exit(1) + } + return value +} + const apiOptions = { - target: `http://${process.env.MARQUEZ_HOST}:${process.env.MARQUEZ_PORT}/` + target: `http://${(environmentVariable("MARQUEZ_HOST"))}:${environmentVariable("MARQUEZ_PORT")}/` } const app = express() const path = __dirname + '/dist' -const port = process.env.WEB_PORT +const port = environmentVariable("WEB_PORT") app.use('/', express.static(path)) app.use('/datasets', express.static(path))