-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.ts
46 lines (41 loc) · 1.1 KB
/
config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { newDatabase } from "./db/db";
import type { Database } from "bun:sqlite";
export type ApiConfig = {
db: Database;
jwtSecret: string;
platform: string;
filepathRoot: string;
assetsRoot: string;
s3Bucket: string;
s3Region: string;
s3CfDistribution: string;
port: string;
};
const pathToDB = envOrThrow("DB_PATH");
const jwtSecret = envOrThrow("JWT_SECRET");
const platform = envOrThrow("PLATFORM");
const filepathRoot = envOrThrow("FILEPATH_ROOT");
const assetsRoot = envOrThrow("ASSETS_ROOT");
const s3Bucket = envOrThrow("S3_BUCKET");
const s3Region = envOrThrow("S3_REGION");
const s3CfDistribution = envOrThrow("S3_CF_DISTRO");
const port = envOrThrow("PORT");
const db = newDatabase(pathToDB);
export const cfg: ApiConfig = {
db: db,
jwtSecret: jwtSecret,
platform: platform,
filepathRoot: filepathRoot,
assetsRoot: assetsRoot,
s3Bucket: s3Bucket,
s3Region: s3Region,
s3CfDistribution: s3CfDistribution,
port: port,
};
function envOrThrow(key: string) {
const envVar = process.env[key];
if (!envVar) {
throw new Error(`${key} must be set`);
}
return envVar;
}