Repository navigation
Expand file tree
/
Copy pathconfig.ts
More file actions
92 lines (81 loc) · 1.93 KB
/
Copy pathconfig.ts
File metadata and controls
92 lines (81 loc) · 1.93 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
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
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: string
host: string
password: string
}
databaseUrl: string
emailClient?: string
session: {
password: string
}
githubRepoToken?: string
public: {
environment: Environment
}
}
export function constructConfig() {
return {
redis: {
port: '6380',
host: 'localhost',
password: 'jabref',
},
databaseUrl: 'postgresql://localhost/jabref',
emailClient: undefined,
session: {
password: 'session_password', // It's too short by design, so that it's not used in production
},
githubRepoToken: undefined,
public: {
environment: getEnvironment(),
},
} satisfies Config
}