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 alexdriaguine committed Jan 23, 2017
1 parent 3af1def commit 7dc8069
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 7dc8069

Please sign in to comment.