hackathon-starter icon indicating copy to clipboard operation
hackathon-starter copied to clipboard

Request log in console update

Open YasharF opened this issue 1 year ago • 3 comments

Besides the request path and the response code some additional information about the request in the console can be helpful for troubleshooting, etc. i.e. request IP to see if the request was from another dev, or perhaps the browser agent.

YasharF avatar Feb 10 '25 12:02 YasharF

Hi @YasharF , How do You want it to be implemented? custom middleware or using "morgan"

sunjay-dev avatar Mar 13 '25 14:03 sunjay-dev

The last time I did an implementation in a private fork I wrote a middleware function for it. In my implementation I made some assumptions that were valid for my specific setup, but we can't assume to be valid in all cases. Hence I am wondering if the middleware would be out-of-scope for hackathon-starter and would need to be in a separate module because there are cases like proxied/WAF setups that would have headers such as x-forwarded-for instead of req.connection.remoteAddress. The problem is that there needs to be additional logic to detect when a header like x-forwarded-for is valid in a secure way as such a header can potentially be spoofed causing a vulnerability.

YasharF avatar Mar 17 '25 23:03 YasharF

I looked more into this. It turned out that the the trust proxy related code that got added as part of this commit https://github.com/sahat/hackathon-starter/commit/34291655d24742b2e1f1bf072898673d8671e200 is sufficient for us to rely on node to figure out the IP address. While looking into it, I realized other issues with the logging of the requests such as missing transfer size and latency. I also realized that it would be helpful to add something about the client browser. Regarding the IP we also need to consider that it can help with debugging, but keeping their record for actual customers in production can cause issues with privacy regulations such as GDPR. All of these required a more of a custom morgan logging. I have addressed these with the following pull request.

PR: https://github.com/sahat/hackathon-starter/pull/1341

YasharF avatar Apr 13 '25 16:04 YasharF