Skip to content

Commit 2fd8d83

Browse files
authored
Add user defined proxy via middleware (facebook#5073)
* Add user defined proxy via middleware * Pass app, instead
1 parent cd75c68 commit 2fd8d83

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

config/paths.js

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = {
5858
appSrc: resolveApp('src'),
5959
yarnLockFile: resolveApp('yarn.lock'),
6060
testsSetup: resolveApp('src/setupTests.js'),
61+
proxySetup: resolveApp('src/setupProxy.js'),
6162
appNodeModules: resolveApp('node_modules'),
6263
publicUrl: getPublicUrl(resolveApp('package.json')),
6364
servedPath: getServedPath(resolveApp('package.json')),
@@ -78,6 +79,7 @@ module.exports = {
7879
appSrc: resolveApp('src'),
7980
yarnLockFile: resolveApp('yarn.lock'),
8081
testsSetup: resolveApp('src/setupTests.js'),
82+
proxySetup: resolveApp('src/setupProxy.js'),
8183
appNodeModules: resolveApp('node_modules'),
8284
publicUrl: getPublicUrl(resolveApp('package.json')),
8385
servedPath: getServedPath(resolveApp('package.json')),
@@ -108,6 +110,7 @@ if (
108110
appSrc: resolveOwn('template/src'),
109111
yarnLockFile: resolveOwn('template/yarn.lock'),
110112
testsSetup: resolveOwn('template/src/setupTests.js'),
113+
proxySetup: resolveOwn('template/src/setupProxy.js'),
111114
appNodeModules: resolveOwn('node_modules'),
112115
publicUrl: getPublicUrl(resolveOwn('package.json')),
113116
servedPath: getServedPath(resolveOwn('package.json')),

config/webpackDevServer.config.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMi
1414
const ignoredFiles = require('react-dev-utils/ignoredFiles');
1515
const config = require('./webpack.config.dev');
1616
const paths = require('./paths');
17+
const fs = require('fs');
1718

1819
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
1920
const host = process.env.HOST || '0.0.0.0';
@@ -81,7 +82,7 @@ module.exports = function(proxy, allowedHost) {
8182
},
8283
// Enable HTTPS if the HTTPS environment variable is set to 'true'
8384
https: protocol === 'https',
84-
host: host,
85+
host,
8586
overlay: false,
8687
historyApiFallback: {
8788
// Paths with dots should still use the history fallback.
@@ -91,11 +92,16 @@ module.exports = function(proxy, allowedHost) {
9192
public: allowedHost,
9293
proxy,
9394
before(app, server) {
95+
if (fs.existsSync(paths.proxySetup)) {
96+
// This registers user provided middleware for proxy reasons
97+
require(paths.proxySetup)(app);
98+
}
99+
94100
// This lets us fetch source contents from webpack for the error overlay
95101
app.use(evalSourceMapMiddleware(server));
96-
97102
// This lets us open files from the runtime error overlay.
98103
app.use(errorOverlayMiddleware());
104+
99105
// This service worker file is effectively a 'no-op' that will reset any
100106
// previous service worker registered for the same host:port combination.
101107
// We do this in development to avoid hitting the production cache if

0 commit comments

Comments
 (0)