-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
config.ts
97 lines (86 loc) · 2.15 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
export enum Environment {
/**
* Locally, on the developers machine.
*/
LocalDevelopment = 'development',
/**
* During continuous integration (Github Action) run.
*/
CI = 'ci',
/**
* During the build for deployment to Azure.
*/
AzureBuild = 'build',
/**
* Pre-production environment, usually from the main branch with production data.
*/
Staging = 'staging',
/**
* Published public state with production data.
*/
Production = 'production',
}
/**
* Taken from https://stackoverflow.com/a/41548441
*/
function enumFromStringValue<T>(
enm: Record<string, T>,
value: string,
): T | undefined {
return (Object.values(enm) as unknown as string[]).includes(value)
? (value as unknown as T)
: undefined
}
function getEnvironment(): Environment {
if (process.env.INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN) {
return Environment.AzureBuild
}
// Github always sets CI variable https://docs.github.com/en/actions/learn-github-actions/environment-variables
if (process.env.CI) {
return Environment.CI
}
if (process.env.NODE_ENV === undefined) return Environment.LocalDevelopment
return (
enumFromStringValue(Environment, process.env.NODE_ENV) ??
Environment.LocalDevelopment
)
}
export interface Config {
redis: {
port: number
host: string
password: string
}
emailClient?: string
session: {
secret: string
}
githubRepoToken: string
public: {
environment: Environment
// Only here to fix typescript error in @nuxtjs/mdc/dist/runtime/components/prose/ProseImg.vue
mdc: {
useNuxtImage: boolean
}
}
}
export function constructConfig() {
return {
redis: {
port: Number(process.env.REDIS_PORT) || 6380,
host: process.env.REDIS_HOST ?? 'localhost',
password: process.env.REDIS_PASSWORD ?? 'jabref',
},
emailClient: process.env.EMAIL_CLIENT,
session: {
secret: process.env.NUXT_SESSION_PASSWORD ?? 'session_secret',
},
githubRepoToken: process.env.GITHUB_REPO_TOKEN ?? 'UNDEFINED',
public: {
environment: getEnvironment(),
mdc: {
useNuxtImage: false,
},
},
} satisfies Config
}