From 8c1e20dba59580a74878b639be5f4105104b02c6 Mon Sep 17 00:00:00 2001 From: Pavel Kolesnikov Date: Sun, 11 Dec 2016 00:48:35 -0800 Subject: [PATCH] Proxy rewrites Origin header to match the target server URL (#1212) * Proxy rewrites Origin header to match the target server URL * Added comments on rewriting Origin header by the proxy middleware --- packages/react-scripts/scripts/start.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/react-scripts/scripts/start.js b/packages/react-scripts/scripts/start.js index b23ffc441e6..c23a2c86d5a 100644 --- a/packages/react-scripts/scripts/start.js +++ b/packages/react-scripts/scripts/start.js @@ -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,