缺少 devServer 代理的 URL 部分
Missing URL parts with devServer proxy
我的 Vue 项目中有以下 vue.config.js:
module.exports = {
devServer: {
proxy: {
'^/api/': {
target: 'https://example.com/api/',
changeOrigin: true,
logLevel: 'debug'
},
}
}
}
所以对 /api/*
的所有请求都应该重定向到 https://example.com/api/*
。不幸的是,代理似乎删除了 api/
:
之后的 URL 部分
[HPM] POST /api/api-token-auth/ -> https://example.com/api/
api-token-auth/
部分发生了什么?
根据 docs 中的语法将所有请求代理到 /api
,创建规则如下:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://example.com',
changeOrigin: true,
logLevel: 'debug'
},
}
}
}
您不应将 /api
路径再次放入 target
中,因为原始路线中 /api
之后的所有内容(包括 /api
都将附加到目标上。
我的 Vue 项目中有以下 vue.config.js:
module.exports = {
devServer: {
proxy: {
'^/api/': {
target: 'https://example.com/api/',
changeOrigin: true,
logLevel: 'debug'
},
}
}
}
所以对 /api/*
的所有请求都应该重定向到 https://example.com/api/*
。不幸的是,代理似乎删除了 api/
:
[HPM] POST /api/api-token-auth/ -> https://example.com/api/
api-token-auth/
部分发生了什么?
根据 docs 中的语法将所有请求代理到 /api
,创建规则如下:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://example.com',
changeOrigin: true,
logLevel: 'debug'
},
}
}
}
您不应将 /api
路径再次放入 target
中,因为原始路线中 /api
之后的所有内容(包括 /api
都将附加到目标上。