-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
199 lines (182 loc) · 4.32 KB
/
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import convict, { type SchemaObj } from 'convict'
import 'dotenv/config'
const dirname = path.dirname(fileURLToPath(import.meta.url))
const oneMinute = 1000 * 60
const oneHour = oneMinute * 60
export const config = convict({
appDir: {
format: String,
default: path.resolve(dirname, '../server')
},
publicDir: {
format: String,
default: path.resolve(dirname, '../../.public')
},
/**
* Server
*/
port: {
format: 'port',
default: 3009,
env: 'PORT'
},
env: {
format: ['development', 'test', 'production'],
default: 'development',
env: 'NODE_ENV'
},
enforceCsrf: {
format: Boolean,
default: process.env.NODE_ENV === 'production',
env: 'ENFORCE_CSRF'
},
/**
* Helper flags
*/
isProduction: {
doc: 'If this application running in the production environment',
format: Boolean,
default: process.env.NODE_ENV === 'production'
},
isDevelopment: {
doc: 'If this application running in the development environment',
format: Boolean,
default: process.env.NODE_ENV !== 'production'
},
isTest: {
doc: 'If this application running in the test environment',
format: Boolean,
default: process.env.NODE_ENV === 'test'
},
/**
* Service
*/
serviceName: {
doc: 'Applications Service Name',
format: String,
default: 'Submit a form to Defra'
},
feedbackLink: {
doc: 'Used in your phase banner. Can be a URL or more commonly mailto mailto:feedback@department.gov.uk',
format: String,
default: null,
env: 'FEEDBACK_LINK'
} as SchemaObj<string>,
phaseTag: {
format: String,
default: 'beta', // Accepts "alpha" |"beta" | ""
env: 'PHASE_TAG'
},
/**
* Session storage
* Redis integration is optional, but recommended for production environments.
*/
sessionTimeout: {
format: Number,
default: oneHour * 24, // 1 day
env: 'SESSION_TIMEOUT'
},
confirmationSessionTimeout: {
format: Number,
default: oneMinute * 20,
env: 'CONFIRMATION_SESSION_TIMEOUT'
},
sessionCookiePassword: {
format: String,
default: null,
sensitive: true,
env: 'SESSION_COOKIE_PASSWORD'
} as SchemaObj<string>,
redis: {
host: {
doc: 'Redis cache host',
format: String,
default: null,
env: 'REDIS_HOST'
} as SchemaObj<string>,
username: {
doc: 'Redis cache username',
format: String,
default: null,
env: 'REDIS_USERNAME'
} as SchemaObj<string>,
password: {
doc: 'Redis cache password',
format: '*',
default: null,
sensitive: true,
env: 'REDIS_PASSWORD'
} as SchemaObj<string>,
keyPrefix: {
doc: 'Redis cache key prefix name used to isolate the cached results across multiple clients',
format: String,
default: null,
env: 'REDIS_KEY_PREFIX'
} as SchemaObj<string>
},
/**
* Email outputs
* Email outputs will use notify to send an email to a single inbox.
*/
notifyTemplateId: {
format: String,
default: null,
env: 'NOTIFY_TEMPLATE_ID'
} as SchemaObj<string>,
notifyAPIKey: {
format: String,
default: null,
env: 'NOTIFY_API_KEY'
} as SchemaObj<string>,
/**
* API integrations
*/
managerUrl: {
format: String,
default: null,
env: 'MANAGER_URL'
} as SchemaObj<string>,
designerUrl: {
format: String,
default: null,
env: 'DESIGNER_URL'
} as SchemaObj<string>,
submissionUrl: {
format: String,
default: null,
env: 'SUBMISSION_URL'
} as SchemaObj<string>,
uploaderUrl: {
format: String,
default: null,
env: 'UPLOADER_URL'
} as SchemaObj<string>,
uploaderBucketName: {
format: String,
default: 'files',
env: 'UPLOADER_BUCKET_NAME'
},
/**
* Logging
*/
logLevel: {
doc: 'Logging level',
format: ['fatal', 'error', 'warn', 'info', 'debug', 'trace', 'silent'],
default: process.env.NODE_ENV === 'development' ? 'error' : 'info',
env: 'LOG_LEVEL'
},
safelist: {
format: Array,
default: ['61bca17e-fe74-40e0-9c15-a901ad120eca.mock.pstmn.io'],
env: 'SAFELIST'
},
stagingPrefix: {
doc: 'Prefix for staging files in S3',
format: String,
default: 'staging',
env: 'STAGING_PREFIX'
}
})
config.validate({ allowed: 'strict' })