Closed toto6321 closed 5 years ago
Again, another weird problem.
const Koa = require('koa') const Router = require('koa-joi-router') const Joi = Router.Joi let router = new Router() router.route({ path: '/user/login', method: 'post', validate: { body: { email: Joi.string().email(), password: Joi.string() }, type: 'json', }, handler: async ctx => { ctx.body = 'success' } }) const route_prefix = '/api/v1' router.prefix(route_prefix) app.use(router.middleware())
To be sure, I also print the router to debug:
Router { routes: [ { path: '/user/login', method: [Array], validate: [Object], handler: [Array] } ], router: Router { opts: { prefix: '/api/v1' }, methods: [ 'HEAD', 'OPTIONS', 'GET', 'PUT', 'PATCH', 'POST', 'DELETE' ], params: {}, stack: [ [Object] ] } }
then I got
pretty upset...
validator need to append .required() ..
Again, another weird problem.
To be sure, I also print the router to debug:
then I got
pretty upset...