Skip to content

Commit

Permalink
Proxy rewrites Origin header to match the target server URL (#1212)
Browse files Browse the repository at this point in the history
* 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 gaearon committed Dec 11, 2016
1 parent 801b955 commit 9d42ffa
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 @@ -201,6 +201,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 9d42ffa

Please sign in to comment.