配置跨域:
historyApiFallback: true,
allowedHosts: 'all',
headers: {
'Access-Control-Allow-Origin': '*'
}
devServer: {
open: true,
host: 'localhost',
port: 8081,
hot: true,
historyApiFallback: true,
allowedHosts: 'all',
headers: {
'Access-Control-Allow-Origin': '*'
},
proxy: {
'/api': {
target: 'http://xxx.xxx.xxx.xxx:8082/',
pathRewrite: {
'^/api': ''
},
changeOrigin: true,
secure: false
}
}
},
该配置文件详细指定了开发服务器如何处理跨域请求。通过设置`historyApiFallback`为true支持HTML5HistoryAPI,`allowedHosts`设为all允许所有主机,`Access-Control-Allow-Origin`设为*允许任何源进行跨域。同时,配置了devServer的代理,将/api路径的请求转发到http://xxx.xxx.xxx.xxx:8082/,并重写了路径,启用changeOrigin以更改源信息,secure参数设为false可能用于忽视HTTPS验证。

2177

被折叠的 条评论
为什么被折叠?



