mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-21 05:20:19 +08:00
Add user defined proxy via middleware (#5073)
* Add user defined proxy via middleware * Pass app, instead
This commit is contained in:
3
packages/react-scripts/config/paths.js
vendored
3
packages/react-scripts/config/paths.js
vendored
@@ -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')),
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user