Vue中devServer.proxy配置失效:请求仍发往8080端口求助
Vue请求代理配置异常:请求仍发往前端8080端口
我正尝试为Vue应用配置请求代理,以便从独立于前端的服务器接收返回的Cookie。前端运行在8080端口,服务器运行在3000端口,但配置devServer.proxy指向3000端口后,请求仍发往8080端口。
当前使用的vue.config.js配置
module.exports = { devServer: { proxy: { '/api': { target: 'https://localhost:3000', ws: true, changeOrigin: true } } } }
Axios请求代码
axios.post(`/api/auth/login/`, loginDetails, { withCredentials: true, credentials: 'include' }) .then(function (response) { console.log('login response: ', response) }) .catch(error => { console.error(error) });
错误表现
控制台错误显示请求仍发往8080端口:
已尝试的其他配置
曾使用如下配置,且请求URL不带前缀,但问题依旧:
module.exports = { devServer: { proxy: 'http://localhost:3000' } }
参考了Vue CLI官方的devServer配置文档。
内容的提问来源于stack exchange,提问作者Jeremy Kung
相关产品推荐
相关产品推荐

