-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.default.ts
More file actions
216 lines (175 loc) · 8.75 KB
/
Copy pathconfig.default.ts
File metadata and controls
216 lines (175 loc) · 8.75 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import fs from 'node:fs'
/**
* Accessing Bluemix variable to get MongoDB info
*/
function getBlueMixConfig() {
const dbLabel = 'mongodb-2.4'
const env = JSON.parse(process.env.VCAP_SERVICES!)
if (env[dbLabel]) {
return env[dbLabel][0].credentials as string
}
}
function getFile(filePath: string | undefined) {
if (filePath !== undefined && filePath) {
try {
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath)
}
} catch (error) {
console.error('Failed to read file', filePath, error)
}
}
return null
}
function getFileEnv(envVariable: string) {
const origVar = process.env[envVariable]
const fileVar = process.env[envVariable + '_FILE']
if (fileVar) {
const file = getFile(fileVar)
if (file) {
return file.toString().split(/\r?\n/, 1)[0].trim()
}
}
return origVar
}
function getBoolean(str: string | undefined, defaultValue = false) {
return str ? str.toLowerCase() === 'true' : defaultValue
}
// Static load at runtime doesn't work with Vite because env var aren't loaded by default;
export const ConfigDefault = {
mongodb: {
// As recommended, a connection String is used instead of the individual params
// More info here: https://docs.mongodb.com/manual/reference/connection-string
// Setting the connection string will only give access to that database
// to see more databases you need to set mongodb.admin to true
// If a connection string options such as server/port/etc are ignored
connectionString: process.env.VCAP_SERVICES ? getBlueMixConfig()! : process.env.ME_CONFIG_MONGODB_URL!,
/** @type {import('mongodb').MongoClientOptions} */
connectionOptions: {
// tls: connect to the server using secure SSL
tls: getBoolean(process.env.ME_CONFIG_MONGODB_SSL),
// tlsAllowInvalidCertificates: validate mongod server certificate against CA
tlsAllowInvalidCertificates: getBoolean(process.env.ME_CONFIG_MONGODB_TLS_ALLOW_CERTS, true),
// tlsCAFile: single PEM file on disk
tlsCAFile: process.env.ME_CONFIG_MONGODB_TLS_CA_FILE,
// tlsCertificateKeyFile: client cert+key PEM file on disk
tlsCertificateKeyFile: process.env.ME_CONFIG_MONGODB_TLS_CERT_KEY_FILE,
// tlsCertificateKeyFilePassword: password for the client key PEM
tlsCertificateKeyFilePassword: process.env.ME_CONFIG_MONGODB_TLS_CERT_KEY_FILE_PASSWORD,
// maxPoolSize: size of connection pool (number of connections to use)
maxPoolSize: 4
},
// set allowDiskUse to true to remove the limit of 100 MB of RAM on each aggregation pipeline stage
// https://www.mongodb.com/docs/v5.0/core/aggregation-pipeline-limits/#memory-restrictions
allowDiskUse: getBoolean(process.env.ME_CONFIG_MONGODB_ALLOW_DISK_USE),
// set admin to true if you want to turn on admin features
// if admin is true, the auth list below will be ignored
// if admin is true, you will need to enter an admin username/password below (if it is needed)
admin: getBoolean(process.env.ME_CONFIG_MONGODB_ENABLE_ADMIN),
// This flag enhance AWS DocumentDB compatibility
awsDocumentDb: getBoolean(process.env.ME_CONFIG_MONGODB_AWS_DOCUMENTDB, false),
// whitelist: hide all databases except the ones in this list (empty list for no whitelist)
whitelist: [],
// blacklist: hide databases listed in the blacklist (empty list for no blacklist)
blacklist: []
},
site: {
// baseUrl: the URL that mongo express will be located at - Remember to add the forward slash at the start and end!
baseUrl: process.env.ME_CONFIG_SITE_BASEURL || '/',
cookieKeyName: 'mongo-express',
cookieSecret: process.env.ME_CONFIG_SITE_COOKIESECRET,
host: process.env.VCAP_APP_HOST || 'localhost',
port: process.env.PORT || 8081,
requestSizeLimit: process.env.ME_CONFIG_REQUEST_SIZE || '50mb',
sessionSecret: process.env.ME_CONFIG_SITE_SESSIONSECRET,
sslCert: process.env.ME_CONFIG_SITE_SSL_CRT_PATH || '',
sslEnabled: getBoolean(process.env.ME_CONFIG_SITE_SSL_ENABLED),
sslKey: process.env.ME_CONFIG_SITE_SSL_KEY_PATH || ''
},
healthCheck: {
// path: the Path that mongo express healthcheck will be serve - Remember to add the forward slash at the start!
path: process.env.ME_CONFIG_HEALTH_CHECK_PATH || '/status'
},
// set useBasicAuth to true if you want to authenticate mongo-express logins
// this will be false unless ME_CONFIG_BASICAUTH_ENABLED is set to the true
useBasicAuth: getBoolean(getFileEnv('ME_CONFIG_BASICAUTH_ENABLED')),
basicAuth: {
username: getFileEnv('ME_CONFIG_BASICAUTH_USERNAME') || 'admin',
password: getFileEnv('ME_CONFIG_BASICAUTH_PASSWORD') || 'pass'
},
useOidcAuth: getBoolean(getFileEnv('ME_CONFIG_OIDCAUTH_ENABLED')),
oidcAuth: {
issuerBaseURL: getFileEnv('ME_CONFIG_OIDCAUTH_ISSUER'),
baseURL: getFileEnv('ME_CONFIG_OIDCAUTH_BASEURL') || process.env.ME_CONFIG_SITE_BASEURL || '/',
clientAuthMethod: 'client_secret_basic',
clientSecret: getFileEnv('ME_CONFIG_OIDCAUTH_CLIENTSECRET'),
clientID: getFileEnv('ME_CONFIG_OIDCAUTH_CLIENTID'),
secret: getFileEnv('ME_CONFIG_OIDCAUTH_SECRET'),
idpLogout: true,
authorizationParams: {
response_type: 'code'
}
},
options: {
// Display startup text on console
console: true,
// TODO add to README
auth: (() => {
// set to true if you want to authenticate mongo-solid logins
// against credentials stored in browser local storage (in addition to basic auth)
const enabled = getBoolean(getFileEnv('ME_CONFIG_AUTH_COOKIE_ENABLED'))
return enabled ? {
enabled,
// key to lookup in browser local storage for username
authCookieKey: getFileEnv('ME_CONFIG_AUTH_COOKIE_KEY') || 'mongo-solid-key',
// key to lookup in browser local storage for password
authCookiePassword: getFileEnv('ME_CONFIG_AUTH_COOKIE_PASSWORD') || 'mongo-solid-password'
} : { enabled }
})(),
// documentsPerPage: how many documents you want to see at once in collection view
documentsPerPage: 10,
// editorTheme: Name of the theme you want to use for displaying documents
// See https://codemirror.net/5/demo/theme.html for all examples
editorTheme: process.env.ME_CONFIG_OPTIONS_EDITORTHEME || 'rubyblue',
// Maximum size of a single property & single row
// Reduces the risk of sending a huge amount of data when viewing collections
maxPropSize: (100 * 1000), // default 100KB
maxRowSize: (1000 * 1000), // default 1MB
// The options below aren't being used yet
// cmdType: the type of command line you want mongo express to run
// values: eval, subprocess
// eval - uses db.eval. commands block, so only use this if you have to
// subprocess - spawns a mongo command line as a subprocess and pipes output to mongo express
cmdType: 'eval',
// subprocessTimeout: number of seconds of non-interaction before a subprocess is shut down
subprocessTimeout: 300,
// readOnly: if readOnly is true, components of writing are not visible.
readOnly: getBoolean(process.env.ME_CONFIG_OPTIONS_READONLY),
// persistEditMode: if set to true, remain on same page after clicked on Save button
persistEditMode: getBoolean(process.env.ME_CONFIG_OPTIONS_PERSIST_EDIT_MODE),
// collapsibleJSON: if set to true, jsons will be displayed collapsible
collapsibleJSON: getBoolean(process.env.ME_CONFIG_OPTIONS_COLLAPSIBLE_JSON, true),
// collapsibleJSONDefaultUnfold: if collapsibleJSON is set to `true`, this defines default level
// to which JSONs are displayed unfolded; use number or "all" to unfold all levels
collapsibleJSONDefaultUnfold: 1,
// gridFSEnabled: if gridFSEnabled is set to 'true', you will be able to manage uploaded files
// ( ak. grids, gridFS )
gridFSEnabled: getBoolean(process.env.ME_CONFIG_SITE_GRIDFS_ENABLED),
// logger: this object will be used to initialize router logger (morgan)
logger: {},
// confirmDelete: if confirmDelete is set to 'true', a modal for confirming deletion is
// displayed before deleting a document/collection
confirmDelete: getBoolean(process.env.ME_CONFIG_OPTIONS_CONFIRM_DELETE),
// noExport: if noExport is set to true, we won't show export buttons
noExport: getBoolean(process.env.ME_CONFIG_OPTIONS_NO_EXPORT),
// fullwidthLayout: if set to true an alternative page layout is used utilizing full window width
fullwidthLayout: getBoolean(process.env.ME_CONFIG_OPTIONS_FULLWIDTH_LAYOUT),
// noDelete: if noDelete is set to true, we won't show delete buttons
noDelete: getBoolean(process.env.ME_CONFIG_OPTIONS_NO_DELETE)
}
}
export const IS_PRODUCTION = process.env.NODE_ENV === 'production'
export type Config = typeof ConfigDefault
export type MongoDb = Config['mongodb'] & {
connectionName?: string
}