Closed willin closed 7 years ago
const Koa = require('koa'); const router = require('koa-joi-router'); const Joi = require('joi'); const parse = require('co-body'); const routes = router(); routes.route([ { method: 'post', path: '/signup', validate: { body: { name: Joi.string().max(100), email: Joi.string().lowercase().email(), password: Joi.string().max(100), _csrf: Joi.string().token() }, type: 'form' }, handler: async (ctx) => { console.log('sth'); // does not print ctx.status = 200; ctx.body = ctx.request.body; } } ]); const app = new Koa(); // add this for test. app.use(async (ctx, next) => { ctx.request.body = await parse.form(ctx); console.log(ctx.request.body); // curl -d "name=test" http://localhost:3000/signup // ^@curl: (52) Empty reply from server // print: { name: 'test' } await next(); // always pendding }); app.use(routes.middleware()); app.listen(3000);
i need a pre-request-handler to check whether the token is valid.
so i have 3 questions:
joi-router has body-parser
co-body i no...
i need a pre-request-handler to check whether the token is valid.
so i have 3 questions: