1、新增全局中间件,会记录异常的请求,主要是400以上的错误日志 2、封装了一个curl请求
$ npm i egg-monitor --save
// {app_root}/config/plugin.js
exports.monitor = {
enable: true,
package: 'egg-monitor',
};
// {app_root}/config/config.default.js
exports.monitor = {
logAllRequest: false // 是否记录所有日志,用于调试模式,默认关闭
};
// default log path
exports.customLogger = {
monitor: {
file: 'egg-monitor.log'
}
}
see config/config.default.js for more detail.
module.exports = class extends Controller {
async index() {
const { ctx } = this;
const host = '';
const options = {
method: 'GET', // 请求方式 默认GET
data: {}, // 请求内容
headers: {}, // 请求头
retry: 1, // 重试次数
retryDelay: 50, // 重试延迟时间
isRetry: function(res) { // 重试判断条件
return !res.status || res.status < 200 || [408, 502, 504].indexOf(parseInt(res.status)) > -1;
},
timeout: [1000, 5000], // 超时时间
contentType: 'json', // 请求内容格式
dataType: 'json' // 响应内容解析方式
};
return ctx.body = await ctx.custom_curl(host, options);
}
}
see httpClient for more detail
Please open an issue here.