Skip to content

Commit 7dc8069

Browse files
kolesalexdriaguine
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 3af1def commit 7dc8069

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: packages/react-scripts/scripts/start.js

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

0 commit comments

Comments
 (0)