Skip to content

Commit

Permalink
Moved size limit to config
Browse files Browse the repository at this point in the history
  • Loading branch information
vasanthv committed Jul 14, 2020
1 parent f2391df commit 6a96ce7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
PORT: process.env.PORT || 3000,
MONGO_URL: process.env.MONGODB_URI || 'mongodb://localhost:27017/jsonbox-io-dev'
SIZE_LIMIT: 50, // mentioned in KB
PORT: process.env.PORT || 3000,
MONGO_URL: process.env.MONGODB_URI || "mongodb://localhost:27017/jsonbox-io-dev",
};
5 changes: 3 additions & 2 deletions src/validators.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const helper = require("./helper");
const config = require("./config");

const Data = require("./db").getInstance();

Expand All @@ -19,8 +20,8 @@ const sizeValidator = (req, res, next) => {
req["bodySize"] = memorySize;

// memorySize is size in bytes. 10KB => 10 * 1024
if (memorySize > 50 * 1024) {
throwError("JSON body is too large. Should be less than 50KB", 413);
if (memorySize > config.SIZE_LIMIT * 1024) {
throwError(`JSON body is too large. Should be less than ${config.SIZE_LIMIT}KB`, 413);
} else if (Array.isArray(req.body)) {
if (req.body.length > 1000) {
throwError("Not more than 1000 records for bulk upload.", 413);
Expand Down

0 comments on commit 6a96ce7

Please sign in to comment.