-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathconfig.js
More file actions
46 lines (38 loc) · 929 Bytes
/
config.js
File metadata and controls
46 lines (38 loc) · 929 Bytes
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
const config = {
email: {
domain: process.env.DOMAIN,
deleteMailsOlderThanDays: process.env.DELETE_MAILS_OLDER_THAN_DAYS || 30
},
imap: {
user: process.env.IMAP_USER,
password: process.env.IMAP_PASSWORD,
host: process.env.IMAP_SERVER,
port: 993,
tls: true,
authTimeout: 3000,
refreshIntervalSeconds: process.env.IMAP_REFRESH_INTERVAL_SECONDS
},
http: {port: normalizePort(process.env.PORT || '3000')}
}
if (!config.imap.user || !config.imap.password || !config.imap.host) {
throw new Error('IMAP is not configured. Use IMAP_* ENV vars.')
}
if (!config.email.domain) {
throw new Error('DOMAIN is not configured. Use ENV vars.')
}
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort(val) {
const port = parseInt(val, 10)
if (isNaN(port)) {
// Named pipe
return val
}
if (port >= 0) {
// Port number
return port
}
return false
}
module.exports = config