fix: Restore env validation for plugins (#6649)
* fix: Restore env validation for plugins * rever
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
// eslint-disable-next-line import/order
|
// eslint-disable-next-line import/order
|
||||||
import environment from "./utils/environment";
|
import environment from "./utils/environment";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
@@ -19,19 +20,20 @@ import Deprecated from "./models/decorators/Deprecated";
|
|||||||
import { getArg } from "./utils/args";
|
import { getArg } from "./utils/args";
|
||||||
|
|
||||||
export class Environment {
|
export class Environment {
|
||||||
protected validationPromise;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.validationPromise = validate(this);
|
process.nextTick(() => {
|
||||||
}
|
void validate(this).then((errors) => {
|
||||||
|
if (errors.length > 0) {
|
||||||
/**
|
let output =
|
||||||
* Allows waiting on the environment to be validated.
|
"Environment configuration is invalid, please check the following:\n\n";
|
||||||
*
|
output += errors.map(
|
||||||
* @returns A promise that resolves when the environment is validated.
|
(error) => "- " + Object.values(error.constraints ?? {}).join(", ")
|
||||||
*/
|
);
|
||||||
public validate() {
|
console.warn(output);
|
||||||
return this.validationPromise;
|
process.exit(1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import services from "./services";
|
|||||||
import { getArg } from "./utils/args";
|
import { getArg } from "./utils/args";
|
||||||
import { getSSLOptions } from "./utils/ssl";
|
import { getSSLOptions } from "./utils/ssl";
|
||||||
import { defaultRateLimiter } from "@server/middlewares/rateLimiter";
|
import { defaultRateLimiter } from "@server/middlewares/rateLimiter";
|
||||||
import { checkEnv, checkPendingMigrations } from "./utils/startup";
|
import { printEnv, checkPendingMigrations } from "./utils/startup";
|
||||||
import { checkUpdates } from "./utils/updates";
|
import { checkUpdates } from "./utils/updates";
|
||||||
import onerror from "./onerror";
|
import onerror from "./onerror";
|
||||||
import ShutdownHelper, { ShutdownOrder } from "./utils/ShutdownHelper";
|
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
|
// This function will only be called once in the original process
|
||||||
async function master() {
|
async function master() {
|
||||||
await checkConnection(sequelize);
|
await checkConnection(sequelize);
|
||||||
await checkEnv();
|
|
||||||
await checkPendingMigrations();
|
await checkPendingMigrations();
|
||||||
|
await printEnv();
|
||||||
|
|
||||||
if (env.TELEMETRY && env.isProduction) {
|
if (env.TELEMETRY && env.isProduction) {
|
||||||
void checkUpdates();
|
void checkUpdates();
|
||||||
|
|||||||
@@ -58,19 +58,7 @@ $ node ./build/server/scripts/20210226232041-migrate-authentication.js
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkEnv() {
|
export async function printEnv() {
|
||||||
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);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (env.isProduction) {
|
if (env.isProduction) {
|
||||||
Logger.info(
|
Logger.info(
|
||||||
"lifecycle",
|
"lifecycle",
|
||||||
|
|||||||
Reference in New Issue
Block a user