背景说明
使用飞冰框架进行开发过程中,发现接口请求存在跨域问题,官方提供了比较好的解决方案,这里记录如下:
解决方案
文档位置
打开浏览器访问:https://ice.work/docs/guide/basic/build,通过CTRL+F搜索关键字proxy
{
"proxy": {
"/**": {
"enable": true,
"target": "http://127.0.0.1:6001"
}
}
}
https://webpack.js.org/configuration/dev-server/#devserverproxy
配置方案
找到build.json
文件追加proxy属性
{
"proxy":{
"/user/**":{
"enable":true,
"target": "http://localhost:8080"
},
"/dept/**":{
"enable":true,
"target": "http://localhost:8080"
}
}
}
项目启动
通过npm run start
启动项目
Get http://localhost:3000/user/test
/user/test
Get http://localhost:3000/dept/test
/dept/test
网友评论