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

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

Closed
piotr-s-brainhub opened this issue Dec 28, 2017 · 4 comments
Closed

Comments

@piotr-s-brainhub
Copy link

piotr-s-brainhub commented Dec 28, 2017

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.

@piotr-s-brainhub
Copy link
Author

I fixed it in #64

@aheckmann
Copy link
Member

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

@chenzhutian
Copy link

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"

@Sleepful
Copy link

Sleepful commented May 5, 2021

@aheckmann that does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants