Skip to content

Commit 8c1e20d

Browse files
kolesrandycoulman
authored andcommitted
Proxy rewrites Origin header to match the target server URL (facebook#1212)
* Proxy rewrites Origin header to match the target server URL * Added comments on rewriting Origin header by the proxy middleware
1 parent fc55342 commit 8c1e20d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

packages/react-scripts/scripts/start.js

+8
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ function addMiddleware(devServer) {
203203
var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {
204204
target: proxy,
205205
logLevel: 'silent',
206+
onProxyReq: function(proxyReq, req, res) {
207+
// Browers may send Origin headers even with same-origin
208+
// requests. To prevent CORS issues, we have to change
209+
// the Origin to match the target URL.
210+
if (proxyReq.getHeader('origin')) {
211+
proxyReq.setHeader('origin', proxy);
212+
}
213+
},
206214
onError: onProxyError(proxy),
207215
secure: false,
208216
changeOrigin: true,

0 commit comments

Comments
 (0)