koajs / bodyparser

Koa body parsing middleware
MIT License
1.31k stars 116 forks source link

Bodyparser returns 404 #99

Closed mustafaekim closed 6 years ago

mustafaekim commented 6 years ago

I am getting 404 when posting to /signup If I remove the bp (bodyParser middleware), it returns 200

Why is that?

import Koa from "koa";
import Router from 'koa-router';
import bodyParser from "koa-bodyparser";

export const public_router = new Router();

async function sign_up(ctx: Koa.Context, next: Function) {
    console.log("Signing up...")
    console.log(ctx.request.body)
    //console.log(ctx.request.rawBody)
    ctx.body = { name: "test" } //ctx.request.body
}

var bp = bodyParser({
    onerror: function (err, ctx) {
        ctx.throw('body parse error', 422);
    }
})

//public_router.use(bp);
public_router
    .post("/signup", bp, sign_up)
mustafaekim commented 6 years ago

if I use app.use(bp) than it works again

mustafaekim commented 6 years ago

sorry my bad! A previous middleware didnt call await before next() ....