Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
26 changes: 14 additions & 12 deletions lib/http/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,24 @@ module.exports = (container) => {
next();
});

// apache request commonlog.
const morgan = require('morgan');
service.use(morgan('common'));

// version path rewrite must happen as a part of Express middleware.
// IMPORTANT: This must run BEFORE body parsing middleware so that route
// matching works correctly on the rewritten paths.
const { versionParser, fieldKeyParser } = require('./middleware');
service.use(versionParser);
service.use(fieldKeyParser);

// automatically parse JSON if it is marked as such. otherwise, just pull the
// plain-text body contents.
const bodyParser = require('body-parser');
const express = require('express');

// 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' });
const defaultJsonLimit = express.json({ type: 'application/json', limit: '250kb' });
const largeJsonLimit = express.json({ type: 'application/json', limit: '100mb' });
const largeJsonUrlMatch = match('/:apiVersion/projects/:id/datasets/:name/entities');
// only apply body-parser middleware to request types which should have a body.
service.patch('/*', defaultJsonLimit);
Expand All @@ -41,15 +52,6 @@ module.exports = (container) => {
return defaultJsonLimit(req, res, next);
});

// apache request commonlog.
const morgan = require('morgan');
service.use(morgan('common'));

// version path rewrite must happen as a part of Express middleware.
const { versionParser, fieldKeyParser } = require('./middleware');
service.use(versionParser);
service.use(fieldKeyParser);

const cookieParser = require('cookie-parser');
service.use(cookieParser());

Expand Down
4 changes: 2 additions & 2 deletions lib/resources/submissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ const multipartErrorHandler = (err, req, res, next) => {
};

// formbody things:
const bodyParser = require('body-parser');
const formParser = bodyParser.urlencoded({ extended: false });
const express = require('express');
const formParser = express.urlencoded({ extended: false });

// util funcs for openRosaSubmission below, mostly just moving baked logic/data off for perf.
const missingXmlProblem = Problem.user.missingMultipartField({ field: XML_SUBMISSION_FILE });
Expand Down
Loading
Loading