Skip to content

Commit

Permalink
Proxy rewrites Origin header to match the target server URL (facebook…
Browse files Browse the repository at this point in the history
…#1212)

* Proxy rewrites Origin header to match the target server URL

* Added comments on rewriting Origin header by the proxy middleware
  • Loading branch information
koles authored and randycoulman committed May 8, 2017
1 parent fc55342 commit 8c1e20d
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/react-scripts/scripts/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ function addMiddleware(devServer) {
var hpm = httpProxyMiddleware(pathname => mayProxy.test(pathname), {
target: proxy,
logLevel: 'silent',
onProxyReq: function(proxyReq, req, res) {
// Browers may send Origin headers even with same-origin
// requests. To prevent CORS issues, we have to change
// the Origin to match the target URL.
if (proxyReq.getHeader('origin')) {
proxyReq.setHeader('origin', proxy);
}
},
onError: onProxyError(proxy),
secure: false,
changeOrigin: true,
Expand Down

0 comments on commit 8c1e20d

Please sign in to comment.