-
Notifications
You must be signed in to change notification settings - Fork 153
/
config.js
374 lines (328 loc) Β· 10.8 KB
/
config.js
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/**
* config.js - Configuration settings for the generated API
*/
const config = {}
config.mongo = {}
/**
* Your app title goes here.
* @type {string}
*/
config.appTitle = 'rest-hapi API'
/**
* Your app version goes here.
* @type {string}
*/
config.version = '1.0.0'
/**
* Flag signifying whether the absolute path to the models directory is provided
* default: false
* @type {boolean}
*/
config.absoluteModelPath = false
/**
* Path to the models directory
* default: 'models'
* @type {string}
*/
config.modelPath = 'models'
/**
* Flag signifying whether the absolute path to the api directory is provided
* @type {boolean}
*/
config.absoluteApiPath = false
/**
* Path to the directory for additional endpoints
* default: 'api'
* @type {string}
*/
config.apiPath = 'api'
/**
* Cors settings for generated endpoints. Can be set to false to disable.
* @type {{additionalHeaders: string[], additionalExposedHeaders: string[]}}
*/
config.cors = {
additionalHeaders: [],
additionalExposedHeaders: []
}
/**
* Mongo settings
* - config.mongo.URI = 'mongodb://localhost/rest_hapi'; (local db, default)
* - config.mongo.options = {} (mongoose options)
*/
config.mongo.URI = 'mongodb://localhost/rest_hapi'
config.mongo.options = {}
/**
* Authentication strategy to be used for all generated endpoints.
* Set to false for no authentication.
* default: false
* @type {boolean/string}
*/
config.authStrategy = false
/**
* If set to false, MANY_MANY associations (including linking model data) will be saved in their own collection in th db. This is useful if a single document
* will be associated with many other documents, which could cause the document size to become very large. For example,
* a business might be associated with thousands of users.
*
* Embedding the associations will be more efficient for population/association queries but less efficient for memory/document size.
*
* This setting can be individually overwritten by setting the "embedAssociation" association property.
* default: false
* @type {boolean}
*/
config.embedAssociations = false
/**
* MetaData options:
* - createdAt: (default: true) date specifying when the document was created.
* - updatedAt: (default: true) date specifying when the document was last updated.
* - deletedAt: (default: true) date specifying when the document was soft deleted.
* - createdBy: (default: false) _id of user that created the document.
* - updatedBy: (default: false) _id of user that last updated the document.
* - updatedBy: (default: false) _id of user that soft deleted the document.
*/
config.enableCreatedAt = true
config.enableUpdatedAt = true
config.enableDeletedAt = true
config.enableCreatedBy = false
config.enableUpdatedBy = false
config.enableDeletedBy = false
/**
* Enables raw $where mongoose queries
* !!WARNING!!: This feature is meant for development ONLY and NOT in production as it provides direct query
* access to your database.
* default: false
* @type {boolean}
*/
config.enableWhereQueries = false
/**
* Enables fields from an associated model to be duplicated. Similar to permanently embedding an associated field within
* the parent model schema. Useful if a parent model needs to be searchable or sortable by an association's field.
* default: false
* @type {boolean}
*/
config.enableDuplicateFields = false
/**
* When true, duplicated fields will update whenever the original field is updated.
* WARNING: This feature can make updates very resource intensive if many documents are duplicating the original field.
* default: false
* @type {boolean}
*/
config.trackDuplicatedFields = false
/**
* When enabled, all create, update, associate, and delete events are recorded in an auditLog collection.
* default: true
* @type {boolean}
*/
config.enableAuditLog = true
/**
* Values added here will be applied to the scope of the auditLog endpoint.
* default: []
* @type {Array}
*/
config.auditLogScope = []
/**
* Specifies the TTL (time to live/lifetime/expiration) of auditLog documents. Accepts values in seconds unless specified
* (Ex: 60 = 60 seconds, '1m' = 1 minute, or '1d' = 1 day)
* See: http://nicoll.io/mongottl/
* default: null (does not expire)
* @type {string}
*/
config.auditLogTTL = null
/**
* Enables policies via mrhorse (https://github.com/mark-bradshaw/mrhorse).
* default: false
* @type {boolean}
*/
config.enablePolicies = false
/**
* Flag signifying whether the absolute path to the policies directory is provided.
* default: false
* @type {boolean}
*/
config.absolutePolicyPath = false
/**
* Path to the directory for mrhorse policies (https://github.com/mark-bradshaw/mrhorse).
* default: 'policies'
* @type {string}
*/
config.policyPath = 'policies'
/**
* Enables document level authorization.
* default: true
* @type {boolean}
*/
config.enableDocumentScopes = true
/**
* If true, modifies the root scope of any document to allow access to the document's creator.
* The scope value added is in the form: "user-{_id}" where "{_id}" is the _id of the user.
* NOTE:
* - This assumes that your authentication credentials (request.auth.credentials) will contain either
* a "user" object with a "_id" property, or the user's _id stored in a property defined by "config.userIdKey".
* - This also assumes that the user creating the document will have "user-{_id}" within their scope.
* - Requires "config.enableDocumentScopes" to be "true".
* - This setting can be individually overwritten by setting the "authorizeDocumentCreator" routeOptions property.
* default: false
* @type {boolean}
*/
config.authorizeDocumentCreator = false
/**
* Same as "authorizeDocumentCreator", but modifies the "readScope" rather than the root scope.
* default: false
* @type {boolean}
*/
config.authorizeDocumentCreatorToRead = false
/**
* Same as "authorizeDocumentCreator", but modifies the "updateScope" rather than the root scope.
* default: false
* @type {boolean}
*/
config.authorizeDocumentCreatorToUpdate = false
/**
* Same as "authorizeDocumentCreator", but modifies the "deleteScope" rather than the root scope.
* default: false
* @type {boolean}
*/
config.authorizeDocumentCreatorToDelete = false
/**
* Same as "authorizeDocumentCreator", but modifies the "associateScope" rather than the root scope.
* default: false
* @type {boolean}
*/
config.authorizeDocumentCreatorToAssociate = false
/**
* This is the path/key to the user _id stored in your request.auth.credentials object.
* default: "user._id"
* @type {string}
*/
config.userIdKey = 'user._id'
/**
* Determines what action takes place when one or more document scope checks fail for requests dealing with multiple
* documents (Ex: deleteMany or list). Options are:
* - true: if one or more documents fail, the request responds with a 403.
* - false: documents that don't pass are simply removed from the request (Ex: not deleted or not retrieved)
* default: false
* @type {boolean}
*/
config.enableDocumentScopeFail = false
/**
* Flag specifying whether to text index all string fields for all models to enable text search.
* WARNING: enabling this adds overhead to add inserts and updates, as well as added storage requirements.
* default: false.
* @type {boolean}
*/
config.enableTextSearch = false
/**
* Soft delete options
* - enableSoftDelete: adds "isDeleted" property to each model. Delete endpoints set "isDeleted" to true
* unless the payload contains { hardDelete: true }, in which case the document is actually deleted (default false)
* - filterDeletedEmbeds: if enabled, associations with "isDeleted" set to true will not populate (default false)
* NOTE: this option is known to be buggy
* @type {boolean}
*/
config.enableSoftDelete = false
config.filterDeletedEmbeds = false
/**
* Validation options:
* default: true
* @type {boolean}
*/
config.enableQueryValidation = true
config.enablePayloadValidation = true
config.enableResponseValidation = true
/**
* Mongoose validation options:
* - enableMongooseRunValidators: enables the runValidators option in Mongoose update calls
* <http://mongoosejs.com/docs/validation.html#update-validators>
* default: false
* @type {boolean}
*/
config.enableMongooseRunValidators = false
/**
* Determines the hapi failAction of each response. Options are:
* - true: responses that fail validation will return a 500 error.
* - false: responses that fail validation will just log the offense and send the response as-is.
* default: false
* @type {boolean}
*/
config.enableResponseFail = false
/**
* If set to true, (and authStrategy is not false) then endpoints will be generated with pre-defined
* scopes based on the model definition.
* default: false
* @type {boolean}
*/
config.generateRouteScopes = false
/**
* If set to true, the scope for each endpoint will be logged when then endpoint is generated.
* default: false
* @type {boolean}
*/
config.logScopes = false
/**
* If set to true, each route will be logged as it is generated.
* default: false
* @type {boolean}
*/
config.logRoutes = false
/**
* Log level options:
* - INTERNAL use it for logging calls and other internal stuff
* - DEBUG recommended to use it for debugging applications
* - NOTE development verbose information (default)
* - INFO minor information
* - LOG significant messages
* - WARNING really important stuff
* - ERROR application business logic error condition
* - FATAL system error condition
*/
config.loglevel = 'NOTE'
/**
* If set to true, the results of each list call will be logged.
* default: false
* @type {boolean}
*/
config.logListResult = false
/**
* If set to true, string values will be truncated to `truncateStringLength` characters in the logs and array values will be trunctated to 30 elements.
* default: false
* @type {boolean}
*/
config.truncateLogs = false
/**
* If `truncateLogs` is set to true, this is the maximum length of a string to be logged.
* default: 100
* @type {number}
*/
config.truncateStringLength = 100
/**
* Set swagger options as per https://github.com/glennjones/hapi-swagger/blob/master/optionsreference.md
* Options set here will override swagger config options below
*
* @type {Object}
*/
config.swaggerOptions = {}
/**
* Determines the initial expansion state of the swagger docs
* - options: 'none', 'list', 'full' (default: 'none')
* default: 'none'
* @type {string}
*/
config.docExpansion = 'none'
/**
* If set to false, SwaggerUI will not be generated.
* - options: 'true', 'false' (default: 'true')
* @type {boolean}
*/
config.enableSwaggerUI = true
/**
* If set to true, swagger will use the https protocol rather than http.
* - options: 'true', 'false' (default: 'false')
* @type {boolean}
*/
config.enableSwaggerHttps = false
/**
* Sets the host used for swagger requests. Useful for an api behind a reverse proxy.
* default: undefined
* @type {boolean}
*/
config.swaggerHost = undefined
module.exports = config