diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index eb15377e71e..61bcecfa3af 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -58,6 +58,7 @@ module.exports = { appSrc: resolveApp('src'), yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveApp('src/setupTests.js'), + proxySetup: resolveApp('src/setupProxy.js'), appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), @@ -78,6 +79,7 @@ module.exports = { appSrc: resolveApp('src'), yarnLockFile: resolveApp('yarn.lock'), testsSetup: resolveApp('src/setupTests.js'), + proxySetup: resolveApp('src/setupProxy.js'), appNodeModules: resolveApp('node_modules'), publicUrl: getPublicUrl(resolveApp('package.json')), servedPath: getServedPath(resolveApp('package.json')), @@ -108,6 +110,7 @@ if ( appSrc: resolveOwn('template/src'), yarnLockFile: resolveOwn('template/yarn.lock'), testsSetup: resolveOwn('template/src/setupTests.js'), + proxySetup: resolveOwn('template/src/setupProxy.js'), appNodeModules: resolveOwn('node_modules'), publicUrl: getPublicUrl(resolveOwn('package.json')), servedPath: getServedPath(resolveOwn('package.json')), diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index b5eb9349aa6..3ff6ad6b40b 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -14,6 +14,7 @@ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMi const ignoredFiles = require('react-dev-utils/ignoredFiles'); const config = require('./webpack.config.dev'); const paths = require('./paths'); +const fs = require('fs'); const protocol = process.env.HTTPS === 'true' ? 'https' : 'http'; const host = process.env.HOST || '0.0.0.0'; @@ -81,7 +82,7 @@ module.exports = function(proxy, allowedHost) { }, // Enable HTTPS if the HTTPS environment variable is set to 'true' https: protocol === 'https', - host: host, + host, overlay: false, historyApiFallback: { // Paths with dots should still use the history fallback. @@ -91,11 +92,16 @@ module.exports = function(proxy, allowedHost) { public: allowedHost, proxy, before(app, server) { + if (fs.existsSync(paths.proxySetup)) { + // This registers user provided middleware for proxy reasons + require(paths.proxySetup)(app); + } + // This lets us fetch source contents from webpack for the error overlay app.use(evalSourceMapMiddleware(server)); - // This lets us open files from the runtime error overlay. app.use(errorOverlayMiddleware()); + // This service worker file is effectively a 'no-op' that will reset any // previous service worker registered for the same host:port combination. // We do this in development to avoid hitting the production cache if