Skip to content

Commit c4c4bff

Browse files
committed
fix(serve): fix non-GET requests match error w/ multi-proxy config
close #1210
1 parent 69ebd80 commit c4c4bff

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

packages/@vue/cli-service/lib/util/prepareProxy.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
5757
return {
5858
target,
5959
context (pathname, req) {
60-
// not a static request
61-
if (req.method !== 'GET') {
62-
return true
63-
}
6460
// is a static asset
6561
if (!mayProxy(pathname)) {
6662
return false
@@ -69,6 +65,10 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
6965
// Explicit context, e.g. /api
7066
return pathname.match(context)
7167
} else {
68+
// not a static request
69+
if (req.method !== 'GET') {
70+
return true
71+
}
7272
// Heuristics: if request `accept`s text/html, we pick /index.html.
7373
// Modern browsers include text/html into `accept` header when navigating.
7474
// However API calls like `fetch()` won’t generally accept text/html.
@@ -112,7 +112,8 @@ module.exports = function prepareProxy (proxy, appPublicFolder) {
112112

113113
// Otherwise, proxy is an object so create an array of proxies to pass to webpackDevServer
114114
return Object.keys(proxy).map(context => {
115-
if (!proxy[context].hasOwnProperty('target')) {
115+
const config = proxy[context]
116+
if (!config.hasOwnProperty('target')) {
116117
console.log(
117118
chalk.red(
118119
'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) {
121122
)
122123
process.exit(1)
123124
}
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)
126127
})
127128
}
128129

0 commit comments

Comments
 (0)