前端的请求信息是这样的:
axios.get('/api/hello') .then(response => console.log(response.data))
webpac.config.js的配置是这样的:
devServer: { proxy: { '/api/*': { target: 'http:localhost:5000', } } }
我想要的是将http://localhost:8080/api/hello的请求发至至http://localhost:5000,但我收到的却是这样的http://localhost:5000/api/hello
我需要怎么配置?
谢谢!
已解决
悬赏分:0
- 解决时间 2021-11-27 16:18
点赞 0反对 0举报 0
收藏 0
分享 0
回答2
最佳
-
你需要在接口的地方引入这个api
devServer: { proxy: { '/api': { target: 'http:localhost:5000', ws: true, // proxy websockets changeOrigin: true, // needed for virtual hosted sites pathRewrite: { '^/api': '' // rewrite path } }, }, disableHostCheck: true, }
在你的api的的js中引入
const BASEURL = "/api"支持 0 反对 0 举报2021-11-27 06:44