-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
41 lines (35 loc) · 883 Bytes
/
index.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
import {Configuration, Configurable, Nested} from 'konvenient'
@Configuration()
class AuthConfiguration {
// When accessed on HttpConfiguration.auth, then
// File key: http.auth.secret
// Env name: SUPER_DUPER_SECRET
@Configurable({
doc: 'Super-duper secret token used for authentication.',
format: String,
env: 'SUPER_DUPER_SECRET',
})
secret = 'CHANGEME'
get secretLongEnough() {
return this.secret.length > 3
}
}
@Configuration()
class HttpConfiguration {
// File key: http.port
// Env name: PORT
@Configurable<number>({
doc: 'The port on which the server listens.',
format: 'port',
env: 'PORT',
result(value: number) {
return value + 1
},
})
port = 8080
@Nested()
auth = new AuthConfiguration()
}
const http = new HttpConfiguration()
console.log(http.port)
console.log(http.auth.secretLongEnough)