egg-joi-fork
v1.0.5
Published
joi validator
Downloads
4
Readme
egg-joi
Install
$ npm i egg-joi --save
Usage
// {app_root}/config/plugin.js
exports.joi = {
enable: true,
package: 'egg-joi',
};
Configuration
// {app_root}/config/config.default.js
exports.joi = {
options: {},
locale: {
'zh-cn': {}
}
};
see config/config.default.js for more detail.
Example
app/validator/sessions
'use strict';
module.exports = app => {
const Joi = app.Joi;
return {
login: Joi.object().keys({
email: Joi.string().email(),
password: Joi.string().regex(/^[a-zA-Z0-9]{3,30}$/)
})
}
};
app/controller/sessions
'use strict';
module.exports = app => {
class SessionsController extends app.Controller {
* login() {
this.ctx.validate(app.validator.sessions.login);
// this.ctx.validate(app.validator.sessions.login, this.ctx.request.body);
// this.ctx.validate(app.validator.sessions.login, this.ctx.request.body, {abortEarly: false}); see [joi] https://github.com/hapijs/joi/blob/v11.0.1/API.md
this.body = 'hello';
}
}
return SessionsController;
};
Questions & Suggestions
Please open an issue here.