$ npm i egg-validate2 --save
// {app_root}/config/plugin.js
exports.validate2 = {
enable: true,
package: 'egg-validate2',
};
// {app_root}/config/config.default.js
exports.validate2 = {
};
see config/config.default.js for more detail.
'use strict';
const Controller = require('egg').Controller;
class HomeController extends Controller {
async index() {
const { ctx } = this;
await ctx.validator().validate({title: [{required: true, message: 'title is required!'}]},ctx.request.query);
ctx.body = 'hi, egg';
}
}
module.exports = HomeController;
See async-validator for more information such as custom rule.
Please open an issue here.