{"action":"created","issue":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/40","repository_url":"https://api.github.com/repos/chimurai/http-proxy-middleware","labels_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/40/labels{/name}","comments_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/40/comments","events_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/40/events","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/40","id":120860522,"number":40,"title":"POST request body is not proxied to the servers","user":{"login":"dejewi","id":967475,"avatar_url":"https://avatars.githubusercontent.com/u/967475?v=3","gravatar_id":"","url":"https://api.github.com/users/dejewi","html_url":"https://github.com/dejewi","followers_url":"https://api.github.com/users/dejewi/followers","following_url":"https://api.github.com/users/dejewi/following{/other_user}","gists_url":"https://api.github.com/users/dejewi/gists{/gist_id}","starred_url":"https://api.github.com/users/dejewi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dejewi/subscriptions","organizations_url":"https://api.github.com/users/dejewi/orgs","repos_url":"https://api.github.com/users/dejewi/repos","events_url":"https://api.github.com/users/dejewi/events{/privacy}","received_events_url":"https://api.github.com/users/dejewi/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":12,"created_at":"2015-12-07T20:29:15Z","updated_at":"2016-09-25T16:11:44Z","closed_at":"2015-12-10T11:53:23Z","body":"I have in my backend defined:\r\n```\r\nvar proxy = proxyMiddleware('/api', {\r\n        target: 'http://somehost.zero',\r\n        proxyTable: {\r\n            '/api/one': 'http://somehost.one',\r\n            '/api/two': 'http://somehost.two',\r\n        }\r\n    });\r\napp.use(proxy);\r\n```\r\n\r\nand when I'm proxing POST request (lets say to the '/api/one': 'http://somehost.one' ) I don't know why but server http://somehost.one get request without body.\r\n\r\nDid you had similar problem?"},"comment":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/comments/249430255","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/40#issuecomment-249430255","issue_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/40","id":249430255,"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-09-25T16:11:44Z","updated_at":"2016-09-25T16:11:44Z","body":"If you can't change the order of the middleware; You can restream the parsed body before proxying the request. This should fix the POST request.\r\n\r\nI modified the recipe from [node-http-proxy/examples/middleware/bodyDecoder-middleware.js](https://github.com/nodejitsu/node-http-proxy/blob/d0e000e1f91a969f1711eb3be7d1acb16c4538df/examples/middleware/bodyDecoder-middleware.js). (https://github.com/nodejitsu/node-http-proxy/pull/1027)\r\n\r\n```javascript\r\n// restream parsed body before proxying\r\nvar restream = function(proxyReq, req, res, options) {\r\n    if (req.body) {\r\n        let bodyData = JSON.stringify(req.body);\r\n        // incase if content-type is application/x-www-form-urlencoded -> we need to change to application/json\r\n        proxyReq.setHeader('Content-Type','application/json');\r\n        proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));\r\n        // stream the content\r\n        proxyReq.write(bodyData);\r\n    }\r\n}\r\n\r\nvar apiProxy = proxyMiddleware('/api', {\r\n    target: 'https://xxx.xxx.xxx.xxx',\r\n    onProxyReq: restream\r\n});\r\n\r\n\r\nvar app = express();\r\n\r\napp.use(bodyParser.json());\r\napp.use(bodyParser.urlencoded());\r\napp.use(apiProxy);                // with restreaming\r\n```\r\n"}}
{"actor":{"display_login":"chimurai"}}