- 安裝http-proxy-middleware
npm install http-proxy-middleware
- 在src下建立setupProxy.js文件
const proxy = require("http-proxy-middleware");
module.exports = function(app) {
app.use(
proxy("/api", {
target: "https://www.coffeecola.cn:8080/",
changeOrigin: true, // needed for virtual hosted sites
ws: true, // proxy websockets
pathRewrite: {
"^/api": ""
}
})
);
};
重啟服務(wù)畦攘,如果后端服務(wù)為Https,使用HTTPS=true npm start啟動