Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
🐛 Strict check bool envs in config (#1046)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Mar 16, 2020
1 parent 699abc2 commit fab1669
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@staart/api",
"version": "1.3.148",
"version": "1.3.149",
"main": "index.js",
"repository": "[email protected]:staart/api.git",
"author": "Anand Chowdhary <[email protected]>",
Expand Down Expand Up @@ -91,5 +91,5 @@
"setup"
],
"snyk": true,
"staart-version": "1.3.148"
"staart-version": "1.3.149"
}
7 changes: 5 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { config } from "dotenv";
config();

export const bool = (val?: string | boolean) =>
String(val).toLowerCase() === "true";

// Server
export const PORT = process.env.PORT ? parseInt(process.env.PORT) : 80;
export const BASE_URL = process.env.BASE_URL || "";
Expand Down Expand Up @@ -62,7 +65,7 @@ export const CACHE_CHECK_PERIOD = process.env.CACHE_CHECK_PERIOD

// Email
export const FRONTEND_URL = process.env.FRONTEND_URL || "https://example.com";
export const ALLOW_DISPOSABLE_EMAILS = !!process.env.DISPOSABLE_EMAIL;
export const ALLOW_DISPOSABLE_EMAILS = bool(process.env.DISPOSABLE_EMAIL);
export const TEST_EMAIL = process.env.TEST_EMAIL || "[email protected]";
/// If you want to use AWS SES to send emails:
export const SES_EMAIL = process.env.SES_EMAIL || "";
Expand Down Expand Up @@ -92,7 +95,7 @@ export const TOKEN_EXPIRY_REFRESH = process.env.TOKEN_EXPIRY_REFRESH || "30d";
export const TOKEN_EXPIRY_API_KEY_MAX = process.env.TOKEN_EXPIRY_API_KEY_MAX
? parseInt(process.env.TOKEN_EXPIRY_API_KEY_MAX)
: 10413685800000; // 2299-12-31 is the default maximum expiry (also what Microsoft uses)
export const DISALLOW_OPEN_CORS = !!process.env.DISALLOW_OPEN_CORS;
export const DISALLOW_OPEN_CORS = bool(process.env.DISALLOW_OPEN_CORS);

// OAuth2 credentials
export const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID || "";
Expand Down

0 comments on commit fab1669

Please sign in to comment.