{"action":"created","issue":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/48","labels_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/48/comments","events_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/48/events","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/48","id":127662148,"number":48,"title":"How to log request and response urls?","user":{"login":"kimmobrunfeldt","id":1232405,"avatar_url":"https://avatars.githubusercontent.com/u/1232405?v=3","gravatar_id":"","url":"https://api.github.com/users/kimmobrunfeldt","html_url":"https://github.com/kimmobrunfeldt","followers_url":"https://api.github.com/users/kimmobrunfeldt/followers","following_url":"https://api.github.com/users/kimmobrunfeldt/following{/other_user}","gists_url":"https://api.github.com/users/kimmobrunfeldt/gists{/gist_id}","starred_url":"https://api.github.com/users/kimmobrunfeldt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kimmobrunfeldt/subscriptions","organizations_url":"https://api.github.com/users/kimmobrunfeldt/orgs","repos_url":"https://api.github.com/users/kimmobrunfeldt/repos","events_url":"https://api.github.com/users/kimmobrunfeldt/events{/privacy}","received_events_url":"https://api.github.com/users/kimmobrunfeldt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-20T11:25:53Z","updated_at":"2016-01-20T13:56:17Z","closed_at":null,"body":"I would like to log each request no matter what status code the target server responded. I'm trying to achieve the following format:\r\n\r\n```js\r\n// Format:\r\n// -->  [METHOD] [PATH_REQUESTED_FROM_PROXY] -> [URL_REQUESTED_FROM_TARGET]\r\n// Example:\r\n// -->  GET /v1/users/123 -> https://my-app.herokuapp.com/api/v1/users/123\r\n```\r\n\r\nMy proxy options are:\r\n```js\r\nvar proxyOpts = {\r\n    target: 'https://my-app.herokuapp.com/',\r\n    pathRewrite: {\r\n        '^/v1' : '/api/v1'\r\n    },\r\n    onProxyReq: function onProxyReq(proxyReq, req, res) {\r\n        // Log outbound request to remote target\r\n        console.log('-->  ', req.method, req.path, '->', proxyReq.baseUrl + proxyReq.path);\r\n    },\r\n    onError: function onError(err, req, res) {\r\n        console.error(err);\r\n        res.status(500);\r\n        res.json({error: 'Error when connecting to remote server.'});\r\n    },\r\n    logLevel: 'debug',\r\n    changeOrigin: true,\r\n    secure: true\r\n};\r\n```\r\n\r\nWhich outputs:\r\n```\r\n-->   GET /api/v1/users/123 -> undefined/api/v1/users/123\r\n```\r\n\r\nProblems:\r\n* `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 server\r\n* `proxyReq.baseUrl` is not defined, I'm not sure what I should use to get the host part of the request."},"comment":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/comments/173211247","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/48#issuecomment-173211247","issue_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/48","id":173211247,"user":{"login":"chimurai","id":655241,"avatar_url":"https://avatars.githubusercontent.com/u/655241?v=3","gravatar_id":"","url":"https://api.github.com/users/chimurai","html_url":"https://github.com/chimurai","followers_url":"https://api.github.com/users/chimurai/followers","following_url":"https://api.github.com/users/chimurai/following{/other_user}","gists_url":"https://api.github.com/users/chimurai/gists{/gist_id}","starred_url":"https://api.github.com/users/chimurai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chimurai/subscriptions","organizations_url":"https://api.github.com/users/chimurai/orgs","repos_url":"https://api.github.com/users/chimurai/repos","events_url":"https://api.github.com/users/chimurai/events{/privacy}","received_events_url":"https://api.github.com/users/chimurai/received_events","type":"User","site_admin":false},"created_at":"2016-01-20T13:56:17Z","updated_at":"2016-01-20T13:56:17Z","body":"Unfortunately the `req.path` information is destroyed after it has been rewritten.\r\n\r\nI do like your suggested improvements to the logging behaviour.\r\n\r\nDo you think logging the rewritten path explicitly is useful?"}}