-
Notifications
You must be signed in to change notification settings - Fork 0
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
How to log response body. #2
Comments
Hello @gulzerr, for now, we don't have access to the response body on middleware, we can only use request body. The best way to do is; function withLog(response) {
console.log(response);
return response;
}
// on route
return withLog(ctx.json(data)) |
Thank you for your prompt response. I will be waiting for response body in the context that I can add in global middleware |
Hello @gulzerr, sorry for implementing it that late but I wanted to ensure performance concerns of the app first, then do next steps. Simple example; const responseTimeMiddleware = createMiddleware(async (ctx, next) => {
const start = Date.now();
// Call all next middleware and handlers.
const response = await next();
const time = Date.now() - start;
console.log(`Response time for url ${ctx.req.url}: ${time}ms`);
// If you call next, it is better if you send the response
return response;
}); All examples; (cache middleware is from Bunicorn, will be in docs soon) |
I am trying to log http request and response bodies with global middleware. Can you please tell me which property/method can return response body from the api? @ragokan
The text was updated successfully, but these errors were encountered: