4
我想代理所有api/
请求http://localhost:3000
使用vue-axios
和vuex
。命令行上的输出表示代理已经创建,但实际上并没有代理正确的地址和404。Vue的代理webpack dev服务器
我已经的WebPack内的以下设置:
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'api/': {
target: 'https://localhost:3000/api',
changeOrigin: true,
pathRewrite: {
'^/api':""
}
}
}
}
而且我的行为的内部文件,我有:
import Vue from 'vue'
export const register = ({ commit }, user) => {
return new Promise((resolve, reject) => {
Vue.axios.post('users', user)
.then(res => {
console.log(res)
debugger
})
.catch(err => {
console.error(err)
debugger
})
})
}
控制台输出表明代理已经确定:
[HPM] Proxy created: /api -> https://localhost:3000/api
[HPM] Proxy rewrite rule created: "^/api" ~> ""
但是当我实际调用函数时,它返回http://localhost:8080/users 404 (Not Found)
这是什么不正确?
我已经咨询
这些解决方案都没有奏效。
我听说这可能是hmr的一个问题,但这似乎不太可能。
任何想法?
我曾尝试以下组合:
'/api': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'api/': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'api/*': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'*/api/**': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'*': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'/api/*': {
target: 'http://localhost:3000',
changeOrigin: true
}
proxy: {
"/api": {
"target": {
"host": "localhost",
"protocol": 'http:',
"port": 3000
},
ignorePath: true,
changeOrigin: true,
secure: false
}
},
同样的问题在这里,仍然没有解决方案 – Plastic