在config/webpackDevServer.config文件下,大概在104行
1 proxy: { 2 ‘/api‘: { 3 target: ‘https://i.news.qq.com/trpc.qqnews_web.pc_base_srv.base_http_proxy‘, 4 changeOrigin: true, 5 pathRewrite: { 6 ‘^/api‘: ‘‘ 7 } 8 } 9 }
1 "proxy":{ 2 "/fans/**":{ 3 "target":"https://easy-mock.com/mock/5c0f31837214cf627b8d43f0/", 4 "changeOrigin": true 5 } 6 }
1 "proxy": "https://easy-mock.com/mock/5c0f31837214cf627b8d43f0/",
1 const proxy = require("http-proxy-middleware"); 2 3 module.exports = function(app) { 4 app.use( 5 proxy("/base/**", { 6 target: "http://45.32.15.21:8090/", 7 changeOrigin: true 8 }) 9 ); 10 app.use( 11 proxy("/fans/**", { 12 target: "https://easy-mock.com/mock/5c0f31837214cf627b8d43f0/", 13 changeOrigin: true 14 }) 15 ); 16 };
create-react-app 构建的项目使用代理 proxy 解决跨域请求
原文:https://www.cnblogs.com/shun1015/p/13747302.html