koajs / joi-router

Configurable, input and output validated routing for koa

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

request hangs if joi-router used together with a body parser

piotr-s-brainhub opened this issue · comments

NodeJS: 8.6.0
npm: 5.2.0
OS: Max OS X 10.12.2
koa: 2.4.1
koa-joi-router: 5.0.0
koa-bodyparser: 4.2.0
koa-body: 2.5.0

For the following app:

const koa = require('koa');
const router = require('koa-joi-router');
const bodyParser = require('koa-bodyparser');

const public = router();

public.route({
  method: 'post',
  path: '/foo',
  validate: {
    type: 'json',
  },
  handler: async (ctx) => {
    ctx.status = 201;
  }
});

const app = new koa();
app.use(bodyParser());
app.use(public.middleware());
app.listen(2999);

the request hangs. The same if koa-body used instead if koa-bodyparser.

I need a koa body parser to be able to use request body in the middlewares.

I fixed it in #64

If you do not want joi-router to parse the payload, do not specify validate.type. See https://github.com/koajs/joi-router#handling-non-validated-input

But if I do not specify the validate.type, the joi-router throw an error says "validate.type must be declared when using validate.body"

@aheckmann that does not work.