项目打完包了,但不方便部署到服务器上,可以先本地跑下看看结果
依赖
"express": "^4.18.2",
"http-proxy-middleware": "^1.0.6",
在项目根目录新建server.js
因为api是 /energyreport/xxx/xxx/xxx?xx=xx
,部分接口是/basic/xx/xx
新版http-proxy-middleware的2.x没看
const express = require('express');
const proxy = require('http-proxy-middleware');
const app = express();
const PORT = 8080;
app.use(express.static('dist'));
const apiProxy = proxy.createProxyMiddleware('/energyreport', {
target: "http://localhost:4200",
changeOrigin: true
});const apiProxy1 = proxy.createProxyMiddleware('/basic', {
target: "http://localhost:4200",
changeOrigin: true
});
app.use(apiProxy);
app.use(apiProxy1);
app.listen(PORT, function(err) {
if (err) {
console.log('err :', err);
} else {
console.log('Listen at http://localhost:' + PORT);
}
});
评论区