chore: Centralize env parsing, validation, defaults, and deprecation notices (#3487)
* chore: Centralize env parsing, defaults, deprecation * wip * test * test * tsc * docs, more validation * fix: Allow empty REDIS_URL (defaults to localhost) * test * fix: SLACK_MESSAGE_ACTIONS not bool * fix: Add SMTP port validation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import invariant from "invariant";
|
||||
import Router from "koa-router";
|
||||
import { escapeRegExp } from "lodash";
|
||||
import env from "@server/env";
|
||||
import { AuthenticationError, InvalidRequestError } from "@server/errors";
|
||||
import Logger from "@server/logging/logger";
|
||||
import {
|
||||
@@ -26,7 +27,7 @@ router.post("hooks.unfurl", async (ctx) => {
|
||||
return (ctx.body = ctx.body.challenge);
|
||||
}
|
||||
|
||||
if (token !== process.env.SLACK_VERIFICATION_TOKEN) {
|
||||
if (token !== env.SLACK_VERIFICATION_TOKEN) {
|
||||
throw AuthenticationError("Invalid token");
|
||||
}
|
||||
|
||||
@@ -89,7 +90,7 @@ router.post("hooks.interactive", async (ctx) => {
|
||||
assertPresent(token, "token is required");
|
||||
assertPresent(callback_id, "callback_id is required");
|
||||
|
||||
if (token !== process.env.SLACK_VERIFICATION_TOKEN) {
|
||||
if (token !== env.SLACK_VERIFICATION_TOKEN) {
|
||||
throw AuthenticationError("Invalid verification token");
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ router.post("hooks.slack", async (ctx) => {
|
||||
assertPresent(team_id, "team_id is required");
|
||||
assertPresent(user_id, "user_id is required");
|
||||
|
||||
if (token !== process.env.SLACK_VERIFICATION_TOKEN) {
|
||||
if (token !== env.SLACK_VERIFICATION_TOKEN) {
|
||||
throw AuthenticationError("Invalid verification token");
|
||||
}
|
||||
|
||||
@@ -289,7 +290,7 @@ router.post("hooks.slack", async (ctx) => {
|
||||
result.document.collection,
|
||||
team,
|
||||
queryIsInTitle ? undefined : result.context,
|
||||
process.env.SLACK_MESSAGE_ACTIONS
|
||||
env.SLACK_MESSAGE_ACTIONS
|
||||
? [
|
||||
{
|
||||
name: "post",
|
||||
|
||||
Reference in New Issue
Block a user