Skip to content

Commit

Permalink
Configurable JSON parser limit (#51)
Browse files Browse the repository at this point in the history
* Configurable JSON parser limit

Signed-off-by: Gabriel Indik <[email protected]>

* Limit in config file

Signed-off-by: Gabriel Indik <[email protected]>
  • Loading branch information
gabriel-indik authored Jan 6, 2022
1 parent 6fb2dfd commit 9e6abbe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const start = async () => {
});

apiApp.use(express.urlencoded({ extended: true }));
apiApp.use(express.json());
apiApp.use(express.json({limit: config.jsonParserLimit ?? utils.constants.DEFAULT_JSON_PARSER_LIMIT}));
apiApp.use('/api/v1', apiRouter);
apiApp.use(errorHandler);

Expand Down
1 change: 1 addition & 0 deletions src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface IConfig {
id: string
endpoint: string
}[]
jsonParserLimit?: string
}

export interface IFile {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ export const constants = {
MAX_EVENT_QUEUE_SIZE: 1000,
HASH_HEADER_NAME: 'dx-hash',
SIZE_HEADER_NAME: 'dx-size',
LAST_UPDATE_HEADER_NAME: 'dx-last-update'
LAST_UPDATE_HEADER_NAME: 'dx-last-update',
DEFAULT_JSON_PARSER_LIMIT: '1mb'
};
const log = new Logger('utils.ts');
axios.defaults.timeout = constants.REST_API_CALL_REQUEST_TIMEOUT;
Expand Down
4 changes: 4 additions & 0 deletions src/schemas/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@
}
}
}
},
"jsonParserLimit": {
"type": "string",
"pattern": "^\\d+(k|K|m|M|g|G|t|T|p|P)?(b|B)$"
}
}
}

0 comments on commit 9e6abbe

Please sign in to comment.