Skip to content

Commit

Permalink
improved environment reader
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasfroeller committed Apr 21, 2024
1 parent c6a056d commit 959bd9c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Propromo Chat

https://s0qb102l.status.cron-job.org

## Description

A chat application for Propromo.
Expand Down
35 changes: 24 additions & 11 deletions environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,31 @@ import { load } from "./deps.ts";
const env = await load();
export const DEV_MODE = env.DEV_MODE === "true";
export const PORT = Number.parseInt(env.PORT ?? "6969");
export const JWT_PRIVATE_KEY = env.JWT_PRIVATE_KEY;
export const JWT_PUBLIC_KEY = env.JWT_PUBLIC_KEY;
export const DATABASE_URL = env.DATABASE_URL;
export let JWT_PRIVATE_KEY: string | undefined = env.JWT_PRIVATE_KEY;
export let JWT_PUBLIC_KEY: string | undefined = env.JWT_PUBLIC_KEY;
export let DATABASE_URL: string | undefined = env.DATABASE_URL;

if (!JWT_PRIVATE_KEY) {
throw new Error("JWT_SECRET is not set");
}
// Check for variables in the process, if there is no .env file present
if (!JWT_PRIVATE_KEY ||
(JWT_PRIVATE_KEY && JWT_PRIVATE_KEY.trim().length === 0) ||
!JWT_PUBLIC_KEY ||
(JWT_PUBLIC_KEY && JWT_PRIVATE_KEY.trim().length === 0) ||
!DATABASE_URL ||
(DATABASE_URL && DATABASE_URL.trim().length === 0)
) {
JWT_PRIVATE_KEY = Deno.env.get("JWT_SECRET");
JWT_PUBLIC_KEY = Deno.env.get("JWT_PUBLIC_KEY");
DATABASE_URL = Deno.env.get("DATABASE_URL");

if (!JWT_PUBLIC_KEY) {
throw new Error("JWT_PUBLIC_KEY is not set");
}
if (!JWT_PRIVATE_KEY) {
throw new Error("JWT_SECRET is not set");
}

if (!JWT_PUBLIC_KEY) {
throw new Error("JWT_PUBLIC_KEY is not set");
}

if (!DATABASE_URL) {
throw new Error("DATABASE_URL is not set");
if (!DATABASE_URL) {
throw new Error("DATABASE_URL is not set");
}
}

0 comments on commit 959bd9c

Please sign in to comment.