koajs / koa-body

koa body parser middleware
MIT License
950 stars 130 forks source link

Causes 'Not Found' #67

Closed MicroDroid closed 7 years ago

MicroDroid commented 7 years ago

Whenever I add koaBody as a middleware, no matter what order, koa returns Not Found all the time

dlau commented 7 years ago

Can you post a code sample please?

Thanks

MicroDroid commented 7 years ago
// router.js

...

const koaBody = require('koa-body');

const AuthController = require('./controllers/auth');

router.post('/login', koaBody, AuthController.login);

// controllers/auth.js

module.exports = {
    login: async function (ctx, next)  {
        console.log(ctx.request.body);

        ctx.body = {
            foo: 1,
        };

        await next();
    },
}
MicroDroid commented 7 years ago

I figured it out, it is koaBody() not koaBody

I will PR this https://github.com/dlau/koa-body#usage-with-koa-router

dlau commented 7 years ago

Was just gonna comment, glad you figured it out!

Indeed the docs are wrong, looking forward to the pr.