Skip to content

Commit

Permalink
fix: add missing config validation (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
radulucut authored Jan 15, 2025
1 parent f14b0eb commit 16934f8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/main/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 16934f8

Please sign in to comment.