1
- import * as dotenv from " dotenv" ;
1
+ import * as dotenv from ' dotenv'
2
2
3
3
/**
4
4
* parse environment vars from the `.env` file if existing
5
5
*/
6
- dotenv . config ( ) ;
6
+ dotenv . config ( )
7
7
8
8
/**
9
9
* configuration management
@@ -13,80 +13,78 @@ export default class Config {
13
13
* mongodb connection configuration
14
14
*/
15
15
static get DB_URI ( ) {
16
- if ( ! process . env [ " DB_URI" ] ) {
17
- throw new Error ( " env: `DB_URI` is missing" ) ;
16
+ if ( ! process . env [ ' DB_URI' ] ) {
17
+ throw new Error ( ' env: `DB_URI` is missing' )
18
18
}
19
- return process . env [ " DB_URI" ] ;
19
+ return process . env [ ' DB_URI' ]
20
20
}
21
21
22
22
/**
23
23
* the server secret salt, mainly used for generating tokens
24
24
*/
25
25
static get SERVER_SECRET ( ) : string {
26
- const secret_salt = process . env [ " SERVER_SECRET" ] ;
26
+ const secret_salt = process . env [ ' SERVER_SECRET' ]
27
27
if ( ! secret_salt ) {
28
- throw new Error ( " env: `SERVER_SECRET` is missing" ) ;
28
+ throw new Error ( ' env: `SERVER_SECRET` is missing' )
29
29
}
30
- return secret_salt ;
30
+ return secret_salt
31
31
}
32
32
33
33
/**
34
34
* the logger level : 'fatal', 'error', 'warning', 'info', 'debug', 'trace'
35
35
*/
36
36
static get LOG_LEVEL ( ) :
37
- | "fatal"
38
- | "error"
39
- | "warning"
40
- | "info"
41
- | "debug"
42
- | "trace" {
43
- return (
44
- ( process . env [ "LOG_LEVEL" ] as any ) ?? ( this . isProd ? "info" : "debug" )
45
- ) ;
37
+ | 'fatal'
38
+ | 'error'
39
+ | 'warning'
40
+ | 'info'
41
+ | 'debug'
42
+ | 'trace' {
43
+ return ( process . env [ 'LOG_LEVEL' ] as any ) ?? ( this . isProd ? 'info' : 'debug' )
46
44
}
47
45
48
46
/**
49
47
* the serving port, default is 8000
50
48
*/
51
49
static get PORT ( ) : number {
52
- return ( process . env . PORT ?? 8000 ) as number ;
50
+ return ( process . env . PORT ?? 8000 ) as number
53
51
}
54
52
55
53
/**
56
54
* in production deploy or not
57
55
*/
58
56
static get isProd ( ) : boolean {
59
- return process . env . NODE_ENV === " production" ;
57
+ return process . env . NODE_ENV === ' production'
60
58
}
61
59
62
60
/**
63
61
* Expired time of function logs, in seconds
64
62
*/
65
63
static get FUNCTION_LOG_EXPIRED_TIME ( ) : number {
66
- return ( process . env . FUNCTION_LOG_EXPIRED_TIME ?? 3600 * 24 * 3 ) as number ;
64
+ return ( process . env . FUNCTION_LOG_EXPIRED_TIME ?? 3600 * 24 * 3 ) as number
67
65
}
68
66
69
67
static get RUNTIME_IMAGE ( ) : string {
70
- return process . env . RUNTIME_IMAGE ;
68
+ return process . env . RUNTIME_IMAGE
71
69
}
72
70
73
71
static get RUNTIME_VERSION ( ) : string {
74
- return require ( " ../package.json" ) ?. version ;
72
+ return require ( ' ../package.json' ) ?. version
75
73
}
76
74
77
75
static get APP_ID ( ) : string {
78
- return process . env . APP_ID ;
76
+ return process . env . APP_ID
79
77
}
80
78
81
79
static get NPM_INSTALL_FLAGS ( ) : string {
82
- return process . env . NPM_INSTALL_FLAGS || "" ;
80
+ return process . env . NPM_INSTALL_FLAGS || ''
83
81
}
84
82
85
83
static get REQUEST_LIMIT_SIZE ( ) : string {
86
- return process . env . REQUEST_LIMIT_SIZE || " 10mb" ;
84
+ return process . env . REQUEST_LIMIT_SIZE || ' 10mb'
87
85
}
88
86
89
87
static get PACKAGES ( ) : string {
90
- return process . env . PACKAGES || "" ;
88
+ return process . env . PACKAGES || ''
91
89
}
92
90
}
0 commit comments