10
10
11
11
const errorOverlayMiddleware = require ( 'react-dev-utils/errorOverlayMiddleware' ) ;
12
12
const evalSourceMapMiddleware = require ( 'react-dev-utils/evalSourceMapMiddleware' ) ;
13
- const noopServiceWorkerMiddleware = require ( 'react-dev-utils/noopServiceWorkerMiddleware' ) ;
14
13
const ignoredFiles = require ( 'react-dev-utils/ignoredFiles' ) ;
15
- const redirectServedPath = require ( 'react-dev-utils/redirectServedPathMiddleware' ) ;
16
14
const paths = require ( './paths' ) ;
17
15
const fs = require ( 'fs' ) ;
18
16
@@ -63,7 +61,6 @@ module.exports = function(proxy, allowedHost) {
63
61
// for some reason broken when imported through Webpack. If you just want to
64
62
// use an image, put it in `src` and `import` it from JavaScript instead.
65
63
contentBase : paths . appPublic ,
66
- contentBasePublicPath : '/test' ,
67
64
// By default files from `contentBase` will not trigger a page reload.
68
65
watchContentBase : true ,
69
66
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
@@ -108,7 +105,14 @@ module.exports = function(proxy, allowedHost) {
108
105
109
106
// If servedPath is not relative redirect to `PUBLIC_URL` or `homepage` from `package.json`
110
107
if ( ! shouldUseRelativeAssetPaths ) {
111
- app . use ( redirectServedPath ( paths . servedPath . slice ( 0 , - 1 ) ) ) ;
108
+ const servedPath = paths . servedPath . slice ( 0 , - 1 ) ;
109
+ app . use ( function redirectServedPathMiddleware ( req , res , next ) {
110
+ if ( req . url === servedPath || req . url . startsWith ( servedPath + '/' ) ) {
111
+ next ( ) ;
112
+ } else {
113
+ res . redirect ( `${ servedPath } ${ req . path } ` ) ;
114
+ }
115
+ } ) ;
112
116
}
113
117
114
118
if ( fs . existsSync ( paths . proxySetup ) ) {
@@ -122,11 +126,17 @@ module.exports = function(proxy, allowedHost) {
122
126
// it used the same host and port.
123
127
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
124
128
// Should match `publicUrl` from Webpack config
125
- app . use (
126
- noopServiceWorkerMiddleware (
127
- shouldUseRelativeAssetPaths ? '' : paths . servedPath . slice ( 0 , - 1 )
128
- )
129
- ) ;
129
+ app . use ( function noopServiceWorkerMiddleware ( req , res , next ) {
130
+ const servedPath = shouldUseRelativeAssetPaths
131
+ ? ''
132
+ : paths . servedPath . slice ( 0 , - 1 ) ;
133
+ if ( req . url === `${ servedPath } /service-worker.js` ) {
134
+ res . setHeader ( 'Content-Type' , 'text/javascript' ) ;
135
+ res . send ( `noop` ) ;
136
+ } else {
137
+ next ( ) ;
138
+ }
139
+ } ) ;
130
140
} ,
131
141
} ;
132
142
} ;
0 commit comments