Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace deprecated https with server, replace deprecated onBeforeSetupMiddleware, onAfterSetupMiddleware with setupMiddlewares #12718

Open
wants to merge 2 commits into
base: wp5
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions packages/react-scripts/config/webpackDevServer.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ 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() ? 'http' : {
type: 'https',
options: getHttpsConfig(),
},
host,
historyApiFallback: {
// Paths with dots should still use the history fallback.
Expand All @@ -101,27 +103,37 @@ module.exports = function (proxy, allowedHost) {
},
// `proxy` is run between `before` and `after` `webpack-dev-server` hooks
proxy,
onBeforeSetupMiddleware(app, server) {
setupMiddlewares(middlewares, devServer) {
// Keep `evalSourceMapMiddleware`
// middlewares before `redirectServedPath` otherwise will not have any effect
// This lets us fetch source contents from webpack for the error overlay
app.use(evalSourceMapMiddleware(server));
middlewares.unshift({
name: 'evalSourceMapMiddleware',
middleware: evalSourceMapMiddleware(devServer),
});

if (fs.existsSync(paths.proxySetup)) {
// This registers user provided middleware for proxy reasons
require(paths.proxySetup)(app);
}
},
onAfterSetupMiddleware(app) {

// Redirect to `PUBLIC_URL` or `homepage` from `package.json` if url not match
app.use(redirectServedPath(paths.publicUrlOrPath));
middlewares.push({
name: 'redirectServedPath',
middleware: 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
app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
middlewares.push({
name: 'noopServiceWorkerMiddleware',
middleware: noopServiceWorkerMiddleware(paths.publicUrlOrPath),
});

return middlewares;
},
};
};