安装插件
npm i http-proxy-middleware
在src目录下添加setupProxy.js文件
Xnip2021-01-27_11-50-18.jpgsetupProxy.js文件内容
const {createProxyMiddleware} = require('http-proxy-middleware');
module.exports = function (app) {
app.use('/api', createProxyMiddleware({
target: 'http://192.168.100.250:9999',
changeOrigin: true,
secure: false,
pathRewrite: { // 请求中去除/api
"^/api": ""
}
}));
}
请求示例
实际请求
http://localhost:3000/api/equip-run-manager/Spring/MVC/entrance/unifier/QueryGroupList
通过跨域后
http:/ /192.168.100.250:9999/equip-run-manager/Spring/MVC/entrance/unifier/QueryGroupList
网友评论