-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig.ts
55 lines (51 loc) · 1.44 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
import dotenv from 'dotenv';
dotenv.config();
interface Configuration {
db: {
host: string;
name: string;
username: string;
password: string;
port: number;
};
allowedOrigins: string[];
autoAcceptConnections: boolean;
server: {
port: number;
address: string;
websocketPort: number;
};
ssl: {
enabled: boolean;
key: string | undefined;
cert: string | undefined;
};
}
const origins =
process?.env?.ALLOWED_ORIGINS?.replace(/\s/g, '')
.toLowerCase()
.split(',')
.filter((it) => it !== '') || [];
const config: Configuration = {
allowedOrigins: origins.length ? Array.from(new Set(origins)) : ['*'],
db: {
username: process.env.MYSQL_USERNAME || 'root',
password: process.env.MYSQL_PASSWORD || '',
name: process.env.MYSQL_DATABASE || 'mysql_note',
host: process.env.MYSQL_HOSTNAME || 'localhost',
port: parseInt(process.env.MYSQL_PORT || '3306', 10) || 3306,
},
autoAcceptConnections:
!!parseInt(process.env.AUTO_ACCEPT_CONNECTION || '', 10) || false,
server: {
port: parseInt(process.env.SERVER_PORT || '2048', 10) || 2048,
address: (process.env.SERVER_ADDRESS || '127.0.0.1').replace(/['"]+/g, ''),
websocketPort: parseInt(process.env.WEBSOCKET_PORT || '80', 10) || 80,
},
ssl: {
enabled: !!parseInt(process.env.SSL_ENABLED || '0', 10) || false,
key: process.env.SSL_KEY,
cert: process.env.SSL_CERTIFICATE,
},
};
export default config;