Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply increased json body limit to entity post endpoint #1123

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/http/service.js
ktuite marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// This file glues together all the middleware and the HTTP REST resources we have
// defined elsewhere into an actual Express service. The only thing it needs in
// order to do this is a valid dependency injection context container.
const { match } = require('path-to-regexp');

module.exports = (container) => {
const service = require('express')();
Expand All @@ -31,7 +32,17 @@ module.exports = (container) => {
// automatically parse JSON if it is marked as such. otherwise, just pull the
// plain-text body contents.
const bodyParser = require('body-parser');
service.use(bodyParser.json({ type: 'application/json', limit: '250kb' }));

// use a default json limit except for URLs that explicitly need a larger limit.
const defaultJsonLimit = bodyParser.json({ type: 'application/json', limit: '250kb' });
const largeJsonLimit = bodyParser.json({ type: 'application/json', limit: '100mb' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's reasonable to hard-code 100mb here for now. Once we take a look at getodk/central#609, we should look into ways to keep this limit consistent across nginx, Backend, and Frontend (e.g., via an environment variable).

const largeJsonUrlMatch = match('/:apiVersion/projects/:id/datasets/:name/entities');

service.use((req, res, next) => {
if (largeJsonUrlMatch(req.url))
ktuite marked this conversation as resolved.
Show resolved Hide resolved
ktuite marked this conversation as resolved.
Show resolved Hide resolved
return largeJsonLimit(req, res, next);
return defaultJsonLimit(req, res, next);
});

// apache request commonlog.
const morgan = require('morgan');
Expand Down
35 changes: 17 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"nodemailer": "~6",
"odata-v4-parser": "~0.1",
"openid-client": "^5.4.3",
"path-to-regexp": "^6.2.2",
"pg": "~8",
"pg-query-stream": "~4",
"pm2": "^5.2.2",
Expand Down