chore: Improve display of configuration errors (#2014)

* chore: Show all configuration errors at once
fix: Remove requirement for deprecated Slack key
fix: Add requirement for UTILS_SECRET

* chore: Add funding/sponsorship message
This commit is contained in:
Tom Moor
2021-04-06 19:29:59 -07:00
committed by GitHub
parent 1101ea428b
commit 5762fb33d9
3 changed files with 122 additions and 31 deletions

View File

@@ -1,6 +1,10 @@
// @flow
require("dotenv").config({ silent: true });
const errors = [];
const boxen = require("boxen");
const chalk = require("chalk");
// If the DataDog agent is installed and the DD_API_KEY environment variable is
// in the environment then we can safely attempt to start the DD tracer
if (process.env.DD_API_KEY) {
@@ -15,10 +19,26 @@ if (
!process.env.SECRET_KEY ||
process.env.SECRET_KEY === "generate_a_new_key"
) {
console.error(
"The SECRET_KEY env variable must be set with the output of `openssl rand -hex 32`"
errors.push(
`The ${chalk.bold(
"SECRET_KEY"
)} env variable must be set with the output of ${chalk.bold(
"$ openssl rand -hex 32"
)}`
);
}
if (
!process.env.UTILS_SECRET ||
process.env.UTILS_SECRET === "generate_a_new_key"
) {
errors.push(
`The ${chalk.bold(
"UTILS_SECRET"
)} env variable must be set with a secret value, it is recommended to use the output of ${chalk.bold(
"$ openssl rand -hex 32"
)}`
);
process.exit(1);
}
if (process.env.AWS_ACCESS_KEY_ID) {
@@ -29,48 +49,66 @@ if (process.env.AWS_ACCESS_KEY_ID) {
"AWS_S3_UPLOAD_MAX_SIZE",
].forEach((key) => {
if (!process.env[key]) {
console.error(`The ${key} env variable must be set when using AWS`);
process.exit(1);
errors.push(
`The ${chalk.bold(
key
)} env variable must be set when using S3 compatible storage`
);
}
});
}
if (process.env.SLACK_KEY) {
if (!process.env.SLACK_SECRET) {
console.error(
`The SLACK_SECRET env variable must be set when using Slack Sign In`
);
process.exit(1);
}
}
if (!process.env.URL) {
console.error(
"The URL env variable must be set to the externally accessible URL, e.g (https://www.getoutline.com)"
errors.push(
`The ${chalk.bold(
"URL"
)} env variable must be set to the fully qualified, externally accessible URL, e.g https://wiki.mycompany.com`
);
process.exit(1);
}
if (!process.env.DATABASE_URL) {
console.error(
"The DATABASE_URL env variable must be set to the location of your postgres server, including authentication and port"
errors.push(
`The ${chalk.bold(
"DATABASE_URL"
)} env variable must be set to the location of your postgres server, including username, password, and port`
);
process.exit(1);
}
if (!process.env.REDIS_URL) {
console.error(
"The REDIS_URL env variable must be set to the location of your redis server, including authentication and port"
errors.push(
`The ${chalk.bold(
"REDIS_URL"
)} env variable must be set to the location of your redis server, including username, password, and port`
);
}
if (errors.length) {
console.log(
chalk.bold.red(
"\n\nThe server could not start, please fix the following configuration errors and try again:\n"
)
);
errors.map((text) => console.log(` - ${text}`));
console.log("\n");
process.exit(1);
}
if (process.env.NODE_ENV === "production") {
console.log("\n\x1b[33m%s\x1b[0m", "Running Outline in production mode.");
console.log(
boxen(
`
Is your team enjoying Outline? Consider supporting future development by sponsoring the project:\n\nhttps://github.com/sponsors/outline
`,
{ padding: 1, margin: 1, borderStyle: "double", borderColor: "green" }
)
);
} else if (process.env.NODE_ENV === "development") {
console.log(
"\n\x1b[33m%s\x1b[0m",
'Running Outline in development mode with hot reloading. To run Outline in production mode set the NODE_ENV env variable to "production"'
chalk.yellow(
`\nRunning Outline in development mode. To run Outline in production mode set the ${chalk.bold(
"NODE_ENV"
)} env variable to "production"\n`
)
);
}