@@ -57,10 +57,6 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
57
57
return {
58
58
target,
59
59
context ( pathname , req ) {
60
- // not a static request
61
- if ( req . method !== 'GET' ) {
62
- return true
63
- }
64
60
// is a static asset
65
61
if ( ! mayProxy ( pathname ) ) {
66
62
return false
@@ -69,6 +65,10 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
69
65
// Explicit context, e.g. /api
70
66
return pathname . match ( context )
71
67
} else {
68
+ // not a static request
69
+ if ( req . method !== 'GET' ) {
70
+ return true
71
+ }
72
72
// Heuristics: if request `accept`s text/html, we pick /index.html.
73
73
// Modern browsers include text/html into `accept` header when navigating.
74
74
// However API calls like `fetch()` won’t generally accept text/html.
@@ -112,7 +112,8 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
112
112
113
113
// Otherwise, proxy is an object so create an array of proxies to pass to webpackDevServer
114
114
return Object . keys ( proxy ) . map ( context => {
115
- if ( ! proxy [ context ] . hasOwnProperty ( 'target' ) ) {
115
+ const config = proxy [ context ]
116
+ if ( ! config . hasOwnProperty ( 'target' ) ) {
116
117
console . log (
117
118
chalk . red (
118
119
'When `proxy` in package.json is as an object, each `context` object must have a ' +
@@ -121,8 +122,8 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
121
122
)
122
123
process . exit ( 1 )
123
124
}
124
- const entry = createProxyEntry ( proxy [ context ] . target , proxy [ context ] . onProxyReq , context )
125
- return Object . assign ( { } , defaultConfig , proxy [ context ] , entry )
125
+ const entry = createProxyEntry ( config . target , config . onProxyReq , context )
126
+ return Object . assign ( { } , defaultConfig , config , entry )
126
127
} )
127
128
}
128
129
0 commit comments