{"action":"closed","issue":{"url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/241","repository_url":"https://api.github.com/repos/chimurai/http-proxy-middleware","labels_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/241/labels{/name}","comments_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/241/comments","events_url":"https://api.github.com/repos/chimurai/http-proxy-middleware/issues/241/events","html_url":"https://github.com/chimurai/http-proxy-middleware/issues/241","id":296386530,"number":241,"title":"Proxying bypass for rewriting  POST/PUT requests?","user":{"login":"leegee","id":512816,"avatar_url":"https://avatars3.githubusercontent.com/u/512816?v=4","gravatar_id":"","url":"https://api.github.com/users/leegee","html_url":"https://github.com/leegee","followers_url":"https://api.github.com/users/leegee/followers","following_url":"https://api.github.com/users/leegee/following{/other_user}","gists_url":"https://api.github.com/users/leegee/gists{/gist_id}","starred_url":"https://api.github.com/users/leegee/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/leegee/subscriptions","organizations_url":"https://api.github.com/users/leegee/orgs","repos_url":"https://api.github.com/users/leegee/repos","events_url":"https://api.github.com/users/leegee/events{/privacy}","received_events_url":"https://api.github.com/users/leegee/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-02-12T14:08:13Z","updated_at":"2018-02-13T07:24:24Z","closed_at":"2018-02-13T07:24:24Z","author_association":"NONE","body":"### Expected behavior\r\n\r\nWhen the `bypass` option is provided and is a function, its return value should either act as a new URL if a string, or be ignored if `false`.\r\n\r\n### Actual behavior\r\n\r\nWorks beautifully for `GET` requests, but the returned string seems to be ignored for `POST` and `PUT` requests.\r\n\r\n### Setup\r\n\r\n* http-proxy-middleware: 0.17.4\r\n* server: _webpack-dev-server 2.11.1\r\n* other relevant modules\r\n\r\n#### proxy middleware configuration\r\n```javascript\r\nconfig.APIS.endpoints.reduce((acc, cv) => {\r\n    acc[`/onewssi/${cv}/v1`] = {\r\n      secure: false,\r\n      headers: config.APIS.proxyHeaders,\r\n      bypass: (req, res, proxyOptions) => {\r\n        // May re-write, rather than bypass, to serve mock data basd on req URI\r\n        let rv = false;\r\n        let found = true;\r\n\r\n        if (req.url.indexOf('/mock') == -1\r\n          && req.url.indexOf('/onewssi') > -1\r\n        ) {\r\n          const requestMethod = req.method.toLowerCase();\r\n          rv = req.url.replace(\r\n            /^\\/+onewssi\\/+(.*?)(\\?.*)?$/,\r\n            (_, pathPart, queryString) => {\r\n              if (queryString) {\r\n                // Original code talking to API has non-encoded QS values:\r\n                queryString = queryString.replace(/\\W/g, '_');\r\n              } else {\r\n                queryString = requestMethod;\r\n              }\r\n\r\n              let url = '/mock/' + pathPart + '/' + queryString + '.json';\r\n\r\n              if (!fs.existsSync(proxyContentBase + url)) {\r\n                url = '/mock/' + pathPart + '/' + requestMethod + '.json';\r\n                if (!fs.existsSync(proxyContentBase + url)) {\r\n                  found = false;\r\n                  console.error(\r\n                    'Dev proxy config error - cannot find mock for requested %s URL,\\n\\t%s\\n\\t%s',\r\n                    req.method, req.url, url\r\n                  );\r\n                }\r\n              }\r\n              return url;\r\n            }\r\n          );\r\n        }\r\n\r\n        if (found) {\r\n          if (rv) {\r\n            rv = rv.replace(/\\/+/g, '/');\r\n            req.method = 'GET';\r\n            console.log('\\nProxy: %s %s –> %s\\n', req.method, req.url, rv);\r\n          } else {\r\n            console.log('Did not rewrite ', req.method, req.url);\r\n          }\r\n        } else {\r\n          console.log('Proxy did not find ', req.method, req.url);\r\n        }\r\n\r\n        return rv;\r\n      }\r\n    };\r\n\r\n    return acc;\r\n  }, {});\r\n```\r\n\r\n"}}
{"actor":{"display_login":"leegee"}}