diff --git a/packages/main/src/config.ts b/packages/main/src/config.ts index bd35fe4..97c9453 100644 --- a/packages/main/src/config.ts +++ b/packages/main/src/config.ts @@ -37,3 +37,31 @@ export const config = { }; export type Config = typeof config; + +function validateConfig (c: Config) { + if (process.env.NODE_ENV !== 'production') { + return; + } + + if (!c.dbHost || !c.dbPort || !c.dbUser || !c.dbPassword || !c.dbDatabase) { + throw new Error('DB_HOST, DB_PORT, DB_USER, DB_PASSWORD and DB_DATABASE environment variable must be set'); + } + + if (!c.slackSigningSecret || !c.slackClientId || !c.slackClientSecret || !c.slackStateSecret) { + throw new Error('SLACK_SIGNING_SECRET, SLACK_CLIENT_ID, SLACK_CLIENT_SECRET and SLACK_STATE_SECRET environment variable must be set'); + } + + if (!c.serverHost) { + throw new Error('SERVER_HOST environment variable must be set'); + } + + if (!c.dashboardUrl || !c.authUrl || !c.authClientId || !c.authClientSecret) { + throw new Error('DASHBOARD_URL AUTH_URL, AUTH_CLIENT_ID and AUTH_CLIENT_SECRET environment variable must be set'); + } + + if (!c.githubPersonalAccessToken || !c.githubBotApiKey || !c.globalpingToken) { + throw new Error('GITHUB_PERSONAL_ACCESS_TOKEN, GITHUB_BOT_API_KEY and GLOBALPING_TOKEN environment variable must be set'); + } +} + +validateConfig(config);