Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fredriklindberg committed Mar 20, 2024
1 parent 90a4166 commit 112d035
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/listener/http-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ export default class HttpListener extends ListenerBase {
private async handleRequest(event: HttpRequestType.request, ctx: HttpRequestContext): Promise<[boolean, number | undefined]>;
private async handleRequest(event: HttpRequestType, ctx: HttpCallbackContext): Promise<[boolean, number | undefined]> {

const captor = new HttpCaptor({
request: ctx.req,
response: (ctx as HttpRequestContext).res,
opts: {
limit: 4*1024,
}
});
//const captor = new HttpCaptor({
// request: ctx.req,
// response: (ctx as HttpRequestContext).res,
// opts: {
// limit: 4*1024,
// }
//});

let statusCode: number | undefined = undefined;
let next = true;
let customLogger: any;
const capture = captor.capture();
//const capture = captor.capture();

ctx.baseUrl = this.getBaseUrl(ctx.req);
if (ctx.baseUrl !== undefined) {
Expand All @@ -164,8 +164,8 @@ export default class HttpListener extends ListenerBase {
next = true;
continue;
}
captor.captureRequestBody = obj.opts?.logBody || false;
captor.captureResponseBody = obj.opts?.logBody || false;
//captor.captureRequestBody = obj.opts?.logBody || false;
//captor.captureResponseBody = obj.opts?.logBody || false;
try {
next = false;
await obj.callback(ctx, () => { next = true });
Expand All @@ -183,25 +183,25 @@ export default class HttpListener extends ListenerBase {
statusCode = 400;
}

customLogger ??= this.logger;
setImmediate(() => {
capture.then((res) => {
if (customLogger === false) {
return;
}
const logEntry = {
operation: 'http-request',
request: res.request,
response: res.response,
client: {
ip: res.client.ip,
remote: res.client.remoteAddr,
},
duration: res.duration,
};
//customLogger.info(logEntry);
});
});
//customLogger ??= this.logger;
//setImmediate(() => {
// capture.then((res) => {
// if (customLogger === false) {
// return;
// }
// const logEntry = {
// operation: 'http-request',
// request: res.request,
// response: res.response,
// client: {
// ip: res.client.ip,
// remote: res.client.remoteAddr,
// },
// duration: res.duration,
// };
// customLogger.info(logEntry);
// });
//});
return [!next, statusCode];
}

Expand Down

0 comments on commit 112d035

Please sign in to comment.