Skip to content

Commit f48a949

Browse files
authored
Merge pull request #174 from saplingjs/feature/default-limit
Implement default limit
2 parents e8b0a1c + 832d525 commit f48a949

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

core/loadConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module.exports = async function (next) {
3636
secret: this.utils.randString(),
3737
showError: true,
3838
strict: false,
39+
limit: 100,
3940
production: 'auto',
4041
db: {
4142
driver: 'Memory'

lib/Storage.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,24 @@ module.exports = class Storage {
497497
/* Check if we're logged in */
498498
this.app.user.isUserAuthenticatedForRoute(request, response);
499499

500+
/* Parse max limit */
501+
const limit = (this.config.limit && this.config.limit > 0) ? this.config.limit : false;
502+
500503
/* Parse limit options */
501504
if ('limit' in request.query) {
502505
options.limit = Number(request.query.limit) || null;
503506

507+
/* If max limit is set in config, ensure we don't go over it */
508+
if (limit && options.limit > limit) {
509+
options.limit = limit;
510+
}
511+
504512
if ('skip' in request.query) {
505513
options.skip = Number(request.query.skip) || null;
506514
}
515+
} else if (limit) {
516+
/* If max limit is set in config, enforce it */
517+
options.limit = limit;
507518
}
508519

509520
/* Parse sorting option */

0 commit comments

Comments
 (0)