-
Notifications
You must be signed in to change notification settings - Fork 852
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 request and response urls? #48
Comments
Unfortunately the For I like your suggested improvements to the logging behaviour. This statement can also be removed, if the original path can be logged: |
I think will be nice to encode the proxy behavior in the log statements too;
So in your use-case; the original url will get logged, its target URI and the pathRewrite arrow.
Let me know what you think. |
Thanks for the quick response! If the default format would be that, I'd be happy! :) Looks good to me. |
@kimmobrunfeldt, I just published v0.11.0 with the logging improvements. Can you verify this change? Let me know if more improvements can be made in logging. |
@chimurai sorry to raise this issue from the dead, but I'm wondering how to use this info in a test. I need to write a test to ensure that URLs are being rewritten correctly by the proxy, and I don't know how to get the rewritten URL from the request or response object, or, alternately, how I would use the log output of the proxy in a test. Any suggestions? |
I have to agree with @mgerring as the current behaviour seems a bit confusing. Ideally I would like to simply obtain the final url requested, however both |
+1 |
@chimurai do we have a way to resolve this ? |
For me, the only solution was to concatenate manually the information
Bad solution but solution :/ |
@materazu I get what you have tried, but this should be something that |
I think too, the callback don't give us the context at this time, it's a good point to search why. If i have time to find this in code, i try to fix it. |
Think with onProxyRes: (proxyRes, req, res) => {
// log original request and proxied request info
const exchange = `[${req.method}] [${proxyRes.statusCode}] ${req.path} -> ${proxyRes.req.protocol}//${proxyRes.req.host}${proxyRes.req.path}`;
console.log(exchange); // [GET] [200] / -> http://www.example.com
}, |
I would like to log each request no matter what status code the target server responded. I'm trying to achieve the following format:
My proxy options are:
Which outputs:
Problems:
req.path
is already converted to the new format with pathRewrite, I would want to log the url which client actually requested from this proxy serverproxyReq.baseUrl
is not defined, I'm not sure what I should use to get the host part of the request.The text was updated successfully, but these errors were encountered: