diff --git a/server/env.ts b/server/env.ts index 89576c498..0c025bde6 100644 --- a/server/env.ts +++ b/server/env.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ // eslint-disable-next-line import/order import environment from "./utils/environment"; import os from "os"; @@ -19,19 +20,20 @@ import Deprecated from "./models/decorators/Deprecated"; import { getArg } from "./utils/args"; export class Environment { - protected validationPromise; - constructor() { - this.validationPromise = validate(this); - } - - /** - * Allows waiting on the environment to be validated. - * - * @returns A promise that resolves when the environment is validated. - */ - public validate() { - return this.validationPromise; + process.nextTick(() => { + void validate(this).then((errors) => { + if (errors.length > 0) { + let output = + "Environment configuration is invalid, please check the following:\n\n"; + output += errors.map( + (error) => "- " + Object.values(error.constraints ?? {}).join(", ") + ); + console.warn(output); + process.exit(1); + } + }); + }); } /** diff --git a/server/index.ts b/server/index.ts index ebc8c7d62..803ef9f93 100644 --- a/server/index.ts +++ b/server/index.ts @@ -19,7 +19,7 @@ import services from "./services"; import { getArg } from "./utils/args"; import { getSSLOptions } from "./utils/ssl"; import { defaultRateLimiter } from "@server/middlewares/rateLimiter"; -import { checkEnv, checkPendingMigrations } from "./utils/startup"; +import { printEnv, checkPendingMigrations } from "./utils/startup"; import { checkUpdates } from "./utils/updates"; import onerror from "./onerror"; import ShutdownHelper, { ShutdownOrder } from "./utils/ShutdownHelper"; @@ -48,8 +48,8 @@ if (env.SERVICES.includes("collaboration")) { // This function will only be called once in the original process async function master() { await checkConnection(sequelize); - await checkEnv(); await checkPendingMigrations(); + await printEnv(); if (env.TELEMETRY && env.isProduction) { void checkUpdates(); diff --git a/server/utils/startup.ts b/server/utils/startup.ts index 4a9a3e508..39bf8ec58 100644 --- a/server/utils/startup.ts +++ b/server/utils/startup.ts @@ -58,19 +58,7 @@ $ node ./build/server/scripts/20210226232041-migrate-authentication.js } } -export async function checkEnv() { - await env.validate().then((errors) => { - if (errors.length > 0) { - Logger.warn( - "Environment configuration is invalid, please check the following:\n\n" - ); - for (const error of errors) { - Logger.warn("- " + Object.values(error.constraints ?? {}).join(", ")); - } - process.exit(1); - } - }); - +export async function printEnv() { if (env.isProduction) { Logger.info( "lifecycle",