From 4c72ffac19d47bbd6d0562fb6d647400710fd4af Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Tue, 1 Jun 2021 13:59:01 +0930 Subject: [PATCH] fix: dynamically get the current environment --- app/cli.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/cli.ts b/app/cli.ts index 4ee16ea08..fb4169b61 100644 --- a/app/cli.ts +++ b/app/cli.ts @@ -63,7 +63,7 @@ const mainOptions = parse(args, { ...options, partial: true, stopAtFirstU const commandOptions = (mainOptions as Flags & { _unknown: string[] })._unknown || []; const command: string = (mainOptions as any).command; // Use the env passed by the user, then the flag inline, then default to production -const environment = process.env.ENVIRONMENT ?? mainOptions.environment ?? 'production'; +const getEnvironment = () => process.env.ENVIRONMENT ?? mainOptions.environment ?? 'production'; const getUnraidApiPid = async () => { // Find all processes called "unraid-api" which aren't this process const pids = await findProcess('name', 'unraid-api', true); @@ -86,12 +86,12 @@ const commands = { // Set envs setEnv('DEBUG', mainOptions.debug); - setEnv('ENVIRONMENT', environment); + setEnv('ENVIRONMENT', getEnvironment()); setEnv('LOG_LEVEL', mainOptions['log-level']); setEnv('LOG_TRANSPORT', mainOptions['log-transport']); setEnv('PORT', mainOptions.port); - console.log(`Starting unraid-api in "${environment}" mode.`); + console.log(`Starting unraid-api in "${getEnvironment()}" mode.`); // Load bundled index file const indexPath = './index.js'; @@ -164,7 +164,7 @@ const commands = { } const stats = await pidusage(unraidApiPid); - console.log(`API has been running for ${prettyMs(stats.elapsed)} and is in "${environment}" mode!`); + console.log(`API has been running for ${prettyMs(stats.elapsed)} and is in "${getEnvironment()}" mode!`); }, async report() { // Find all processes called "unraid-api" which aren't this process @@ -173,7 +173,7 @@ const commands = { console.log( dedent` <-----UNRAID-API-REPORT-----> - Environment: ${environment} + Environment: ${getEnvironment()} Node API version: ${version} (${unraidApiPid ? 'running' : 'stopped'}) Unraid version: ${unraidVersion}