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
|
||||
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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user