koa-mongo-rest icon indicating copy to clipboard operation
koa-mongo-rest copied to clipboard

incompatible with koabodyparser

Open mgenev opened this issue 9 years ago • 6 comments

when I add app.use(bodyParser) all the methods in koa-mongo-rest which look for the body start failing silently and the request is left hanging.

I'm not sure how to deal with that yet, so I'm opening for discussion.

mgenev avatar May 28 '15 19:05 mgenev

koa-mongo-rest uses co-body, so maybe you ran into some conflict there, if bodyParsers modified request in a way that makes it unreadable to co-body.

tomaash avatar May 29 '15 14:05 tomaash

RIght, so one way to fix this would be to add koabodyparser as a dependency to koa-mongo-rest instead of parsing the body in it, that way both can work, otherwise i'm not sure how to make them compatible

mgenev avatar May 29 '15 16:05 mgenev

For myself, I don't care if body is parsed in koa-mongo-rest by co-body or koabodyparser. You can give it a try. But it has to work even if my application does not use koabodyparser.

tomaash avatar May 29 '15 17:05 tomaash

I tried koa-body-parser as well, and it does not work for me for some reason. However, it's extremely simple module. I ended up writing my own body parsing middleware based on it, it looks like this and works with koa-mongo rest:

app.use(function *(next) {
  const encoding = 'transfer-encoding' in this.req.headers;
  if (encoding || this.request.length) {
    this.request.body = yield parse(this, {
      limit: '1kb'
    });
  }
  yield next;
});

tomaash avatar May 30 '15 09:05 tomaash

Fixed in 0.3.4, please use my fork: https://github.com/tomaash/koa-body-parser

tomaash avatar May 30 '15 17:05 tomaash

This could probably be resolved?

parris avatar Aug 04 '15 06:08 parris