diff --git a/packages/react-scripts/config/getHttpsConfig.js b/packages/react-scripts/config/getHttpsConfig.js index 4fec7936b2f..2c529c0ee37 100644 --- a/packages/react-scripts/config/getHttpsConfig.js +++ b/packages/react-scripts/config/getHttpsConfig.js @@ -60,15 +60,18 @@ function getHttpsConfig() { if (isHttps && SSL_CRT_FILE && SSL_KEY_FILE) { const crtFile = path.resolve(paths.appPath, SSL_CRT_FILE); const keyFile = path.resolve(paths.appPath, SSL_KEY_FILE); - const config = { + const options = { cert: readEnvFile(crtFile, 'SSL_CRT_FILE'), key: readEnvFile(keyFile, 'SSL_KEY_FILE'), }; - validateKeyAndCerts({ ...config, keyFile, crtFile }); - return config; + validateKeyAndCerts({ ...options, keyFile, crtFile }); + return { + type: 'https', + options, + }; } - return isHttps; + return 'http'; } module.exports = getHttpsConfig; diff --git a/packages/react-scripts/config/webpackDevServer.config.js b/packages/react-scripts/config/webpackDevServer.config.js index 522a81b9b2b..66f4b663166 100644 --- a/packages/react-scripts/config/webpackDevServer.config.js +++ b/packages/react-scripts/config/webpackDevServer.config.js @@ -20,7 +20,6 @@ const host = process.env.HOST || '0.0.0.0'; const sockHost = process.env.WDS_SOCKET_HOST; const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws' const sockPort = process.env.WDS_SOCKET_PORT; - module.exports = function (proxy, allowedHost) { const disableFirewall = !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true'; @@ -98,8 +97,7 @@ module.exports = function (proxy, allowedHost) { // remove last slash so user can land on `/test` instead of `/test/` publicPath: paths.publicUrlOrPath.slice(0, -1), }, - - https: getHttpsConfig(), + server: getHttpsConfig(), host, historyApiFallback: { // Paths with dots should still use the history fallback. @@ -109,27 +107,30 @@ module.exports = function (proxy, allowedHost) { }, // `proxy` is run between `before` and `after` `webpack-dev-server` hooks proxy, - onBeforeSetupMiddleware(devServer) { - // Keep `evalSourceMapMiddleware` - // middlewares before `redirectServedPath` otherwise will not have any effect - // This lets us fetch source contents from webpack for the error overlay - devServer.app.use(evalSourceMapMiddleware(devServer)); - + setupMiddlewares(middlewares, devServer) { if (fs.existsSync(paths.proxySetup)) { // This registers user provided middleware for proxy reasons require(paths.proxySetup)(devServer.app); } - }, - onAfterSetupMiddleware(devServer) { - // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match - devServer.app.use(redirectServedPath(paths.publicUrlOrPath)); - // 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 - // it used the same host and port. - // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432 - devServer.app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath)); + middlewares.unshift( + // Keep `evalSourceMapMiddleware` + // middlewares before `redirectServedPath` otherwise will not have any effect + // This lets us fetch source contents from webpack for the error overlay + evalSourceMapMiddleware(devServer) + ); + + middlewares.push( + // Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match + redirectServedPath(paths.publicUrlOrPath), + // 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 + // https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432 + noopServiceWorkerMiddleware(paths.publicUrlOrPath) + ); + + return middlewares; }, }; }; diff --git a/packages/react-scripts/package.json b/packages/react-scripts/package.json index a98cb879b95..e4e21ea6fdf 100644 --- a/packages/react-scripts/package.json +++ b/packages/react-scripts/package.json @@ -72,7 +72,7 @@ "tailwindcss": "^3.0.2", "terser-webpack-plugin": "^5.2.5", "webpack": "^5.64.4", - "webpack-dev-server": "^4.6.0", + "webpack-dev-server": "^4.7.3", "webpack-manifest-plugin": "^4.0.2", "workbox-webpack-plugin": "^6.4.1" },