react中配置setupProxy.js后localhost拒绝访问的问题
//低版本配置代码 const proxy = require('http-proxy-middleware') module.exports = function(app){ app.use( proxy('/api',{ target:'http://localhost:5000', changeOrigin:true, pathRewrite:{'^/api':''} }), proxy('/api2',{ target:'http://localhost:5001', changeOrigin: true, pathRewrite:{'^/api2':''} }) ) }
修改为最新的配置,即可解决问题
//新版配置代码 const {createProxyMiddleware} = require('http-proxy-middleware') module.exports = function(app){ app.use( createProxyMiddleware('/api1',{ target:'http://localhost:5000', changeOrigin:true, pathRewrite:{'^/api1':''} }) ) }