egg-validate2
Install
$ npm i egg-validate2 --save
Usage
// {app_root}/config/plugin.js
exports.validate = {
enable: true,
package: 'egg-validate2',
};
Configuration
// {app_root}/config/config.default.js
exports.validate = {
};
see config/config.default.js for more detail.
Example
'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.
Questions & Suggestions
Please open an issue here.