测试接口
配置
正确访问路径:https://api.github.com/users// 请求fetch("/api/users").then((res) => res.json()).then((res) => console.log(res));// 配置devServer: {proxy: {'/api': {target: 'https://api.github.com',pathRewrite: {'^/api': ''},changeOrigin: true,}}}
changeOrigin: true
这个配置项的作用是将请求的origin设置为target
原因:有些后端服务胡对origin做特别处理,不允许访问,从而报500错误,而 changeOrigin: true 可以将orgin设置为target指定的origin [ 可能有误 ]
