Custom proxy in CRA v2 returns 403 on POST
Created by: ghengeveld
Is this a bug report?
Yes.
Environment
Environment: OS: macOS 10.14 Node: 8.9.0 Yarn: Not Found npm: 6.4.1 Watchman: Not Found Xcode: Not Found Android Studio: 2.2 AI-145.3537739
Packages: (wanted => installed) react: 16.5.1 => 16.5.1 react-dom: 16.5.1 => 16.5.1 react-scripts: 2.0.5 => 2.0.5
[project root]
└─┬ http-proxy-middleware@0.19.0
└── http-proxy@1.17.0
Steps to Reproduce
Previously, using react-scripts@1.1.5, I was using:
"proxy": {
"/checkout": {
"target": "https://subdomain.example.org",
"changeOrigin": true,
"pathRewrite": {
"^/checkout": ""
}
},
}
After upgrading I followed the upgrade guide and created this src/setupProxy.js
:
const proxy = require("http-proxy-middleware")
module.exports = app => {
app.use(
proxy("/checkout", {
target: "https://subdomain.example.org",
changeOrigin: true,
pathRewrite: {
"^/checkout": "",
},
})
)
}
Expected Behavior
All requests from localhost:3000/checkout should be properly proxied to https://subdomain.example.org
Actual Behavior
All GET
requests work as intended. However, a POST
request returns immediately with a 403 Forbidden
. Before upgrading to CRA v2 this worked fine.
Reproducible Demo
I would love to provide one, but would take considerable effort to realise. This issue has already cost me my entire working day. I have already attempted to downgrade both http-proxy-middleware
and the underlying http-proxy
to the versions used in CRA v1.1.5, to no avail. I've also extensively reviewed the relevant source code of react-scripts
, react-dev-utils
and http-proxy-middleware
, but was unable to identify any change that can explain this behavior.