Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 支持moreDebuggerInfo配置 #31

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
websocket mode support complex url.
1.0.5 add headerExtension to `http` and `websocket` mode.
1.0.7 error message typo.
1.0.10 config.defaultErrorCode
1.0.10 config.defaultErrorCode
2.0.20 feature: Add more logInfo config
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ HcProxy.prototype.mount = function (router, app) {
let beforeRequest = u.beforeRequest;
let beforeResponse = u.beforeResponse;
let statusCode = u.return;
let serviceOpt = u.serviceOpt || service.serviceOpt || {}
let serviceOpt = u.serviceOpt || service.serviceOpt || {};
let moreDebuggerInfo = u.moreDebuggerInfo;

return {
serviceName,
Expand All @@ -189,6 +190,7 @@ HcProxy.prototype.mount = function (router, app) {
beforeRequest,
beforeResponse,
serviceOpt,
moreDebuggerInfo
};
});

Expand Down
18 changes: 18 additions & 0 deletions lib/service_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,24 @@ module.exports = function (u, proxyHeaders) {
beforeRequest(req, options, u);
}
log.info(`[hc-proxy] ${req.method} ${qpath} -> ${options.url}`);

if (u.moreDebuggerInfo) {
const {filter} = u.moreDebuggerInfo;
const {headers} = filter;
let needLog = true;
for (let header in headers) {
if (!needLog) {
break;
}
if (req.headers[header.toLocaleLowerCase()] !== headers[header]) {
needLog = false;
}
}
if (needLog) {
log.info(`[moreDebugger] body -> ${JSON.stringify(req.body)} headers -> ${JSON.stringify(req.headers)}`)
}
}

let optKeys = ['pipe'];
optKeys.forEach((key) => {
delete options[key];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hc-proxy",
"version": "2.0.19",
"version": "2.0.20",
"description": "honeycomb api proxy express middleware.",
"main": "index.js",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,17 @@ options.service 详情
/* delete方法使用querystring代理, 默认为true */
useQuerystringInDelete: {Boolean},
/** 用户覆盖的urllibOption,覆盖系统默认值,优先级: service.api.urllibOption > service.urllibOption > hc-proxy默认设置 */
urllibOption: {Object}
urllibOption: {Object},
/** filter全部命中之后才会出日志
* {
* filter: {
* headers: {
* key: value
* }
* }
* }
*/
moreDebuggerInfo: {Object}
}
]
}
Expand Down
Loading