'use strict'; /** * 自定义启动文件 * * @author CaiAoLin * @date 2017/8/29 * @version */ const BaseService = require('./app/base/base_service'); const BaseController = require('./app/base/base_controller'); module.exports = app => { // 数据模型基类 app.BaseService = BaseService; // 控制器基类 app.BaseController = BaseController; // 自定义手机校验规则 app.validator.addRule('mobile', (rule, value) => { try { const regPhone = /^1[3456789]\d{9}$/; const allowEmpty = rule.allowEmpty === true; if (allowEmpty && value === '') { return true; } if (!(value.length === 11 && regPhone.test(value))) { throw 'please enter the correct phone number'; } } catch (error) { return error; } }); // 自定义手机IP规则 app.validator.addRule('ip', (rule, value) => { try { const allowEmpty = rule.allowEmpty === true; if (allowEmpty && value === '') { return true; } const regIP = /^(\d{2,})\.(\d+)\.(\d+)\.(\d+)$/; if (!regIP.test(value)) { throw 'please enter the correct ip address'; } } catch (error) { return error; } }); app.min = app.config.min ? 'min.' : ''; app.config.bodyParser.jsonLimit = '5mb'; app.config.bodyParser.formLimit = '6mb'; };