Merge pull request #47 from mailvelope/dev/fix-parsing

Use co-body directly instead of koa-body (which uses co-body under th…
This commit is contained in:
Tankred Hase 2017-08-27 16:54:34 +08:00 committed by GitHub
commit d80108915e
5 changed files with 5 additions and 10 deletions

View File

@ -21,9 +21,9 @@
}, },
"dependencies": { "dependencies": {
"addressparser": "^1.0.1", "addressparser": "^1.0.1",
"co-body": "^5.1.1",
"config": "^1.20.4", "config": "^1.20.4",
"koa": "^2.3.0", "koa": "^2.3.0",
"koa-body": "^2.3.0",
"koa-router": "^7.2.1", "koa-router": "^7.2.1",
"koa-static": "^4.0.1", "koa-static": "^4.0.1",
"mongodb": "^2.2.31", "mongodb": "^2.2.31",

View File

@ -45,7 +45,6 @@ router.del('/api/v1/key', ctx => rest.remove(ctx));
app.on('error', middleware.logUnknownError); app.on('error', middleware.logUnknownError);
app.use(middleware.upgradeToHTTPS); app.use(middleware.upgradeToHTTPS);
app.use(middleware.setHTTPResponseHeaders); app.use(middleware.setHTTPResponseHeaders);
app.use(middleware.parseBody());
app.use(router.routes()); app.use(router.routes());
app.use(router.allowedMethods()); app.use(router.allowedMethods());
app.use(serve(`${__dirname}/../static`)); app.use(serve(`${__dirname}/../static`));

View File

@ -19,7 +19,6 @@
const log = require('winston'); const log = require('winston');
const config = require('config'); const config = require('config');
const koaBody = require('koa-body');
const util = require('../service/util'); const util = require('../service/util');
exports.upgradeToHTTPS = async function(ctx, next) { exports.upgradeToHTTPS = async function(ctx, next) {
@ -51,11 +50,6 @@ exports.setHTTPResponseHeaders = async function(ctx, next) {
await next(); await next();
}; };
exports.parseBody = () => koaBody({
multipart: true,
formLimit: '1mb'
});
exports.logUnknownError = function(error, ctx) { exports.logUnknownError = function(error, ctx) {
if (error.status) { if (error.status) {
log.verbose('middleware', `Request failed: ${error.status} ${error.message}`); log.verbose('middleware', `Request failed: ${error.status} ${error.message}`);

View File

@ -17,6 +17,7 @@
'use strict'; 'use strict';
const parse = require('co-body');
const util = require('../service/util'); const util = require('../service/util');
/** /**
@ -37,7 +38,7 @@ class HKP {
* @param {Object} ctx The koa request/response context * @param {Object} ctx The koa request/response context
*/ */
async add(ctx) { async add(ctx) {
const publicKeyArmored = ctx.request.body.keytext; const {keytext: publicKeyArmored} = await parse.form(ctx, {limit: '1mb'});
if (!publicKeyArmored) { if (!publicKeyArmored) {
ctx.throw(400, 'Invalid request!'); ctx.throw(400, 'Invalid request!');
} }

View File

@ -17,6 +17,7 @@
'use strict'; 'use strict';
const parse = require('co-body');
const util = require('../service/util'); const util = require('../service/util');
/** /**
@ -37,7 +38,7 @@ class REST {
* @param {Object} ctx The koa request/response context * @param {Object} ctx The koa request/response context
*/ */
async create(ctx) { async create(ctx) {
const {publicKeyArmored} = ctx.request.body; const {publicKeyArmored} = await parse.json(ctx, {limit: '1mb'});
if (!publicKeyArmored) { if (!publicKeyArmored) {
ctx.throw(400, 'Invalid request!'); ctx.throw(400, 'Invalid request!');
} }