-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
67 lines (61 loc) · 1.65 KB
/
app.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
import 'dotenv/config';
import { AppConfig } from '@overture-stack/lyric';
import { authHandler } from '../auth/handler.js';
export const getServerConfig = () => {
return {
port: process.env.PORT || 3030,
allowedOrigins: process.env.ALLOWED_ORIGINS,
};
};
export const getBoolean = (env: string | undefined, defaultValue: boolean): boolean => {
switch ((env ?? '').toLocaleLowerCase()) {
case 'true':
return true;
case 'false':
return false;
default:
return defaultValue;
}
};
const getRequiredConfig = (name: string) => {
const value = process.env[name];
if (!value) {
throw new Error(`No Environment Variable provided for required configuration parameter '${name}'`);
}
return value;
};
export const appConfig: AppConfig = {
db: {
host: getRequiredConfig('DB_HOST'),
port: Number(getRequiredConfig('DB_PORT')),
database: getRequiredConfig('DB_NAME'),
user: getRequiredConfig('DB_USER'),
password: getRequiredConfig('DB_PASSWORD'),
},
features: {
audit: {
enabled: getBoolean(process.env.AUDIT_ENABLED, true),
},
recordHierarchy: {
pluralizeSchemasName: getBoolean(process.env.PLURALIZE_SCHEMAS_ENABLED, true),
},
},
idService: {
useLocal: getBoolean(process.env.ID_USELOCAL, true),
customAlphabet: process.env.ID_CUSTOM_ALPHABET || '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ',
customSize: Number(process.env.ID_CUSTOM_SIZE) || 21,
},
schemaService: {
url: getRequiredConfig('LECTERN_URL'),
},
limits: {
fileSize: process.env.UPLOAD_LIMIT || '10mb',
},
logger: {
level: process.env.LOG_LEVEL || 'info',
},
auth: {
enabled: getBoolean(process.env.AUTH_ENABLED, true),
customAuthHandler: authHandler,
},
};