forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
39 lines (36 loc) · 1.01 KB
/
config.ts
File metadata and controls
39 lines (36 loc) · 1.01 KB
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
export type Config = {
assets: boolean
db: string
debug: boolean
env: 'development' | 'production' | 'test'
proxyOrigin: string | undefined
staging: boolean
}
function getDefaultDatabase(env: Config['env']): string {
if (env === 'production') {
throw new Error('Set DATABASE_URL with PostgreSQL credentials')
} else if (env === 'test') {
return 'memory://'
} else {
return 'file://./db/pgdata'
}
}
export function getConfig(from: Record<string, string | undefined>): Config {
let env = from.NODE_ENV ?? 'development'
if (env !== 'test' && env !== 'production' && env !== 'development') {
throw new Error('Unknown NODE_ENV')
}
let proxyOrigin = from.PROXY_ORIGIN
if (!proxyOrigin && env === 'development') {
proxyOrigin = '^http:\\/\\/localhost:\\d+$'
}
return {
assets: !!from.ASSETS,
db: from.DATABASE_URL ?? getDefaultDatabase(env),
debug: !!from.DEBUG,
env,
proxyOrigin,
staging: !!from.STAGING
}
}
export const config = getConfig(process.env)