cnetong-core-frontend
Version:
```js // 在npm项目中的main.js文件中加入以下代码 import Base from "cnetong-core-frontend";
24 lines (22 loc) • 549 B
JavaScript
/**
* 创建一个服务代理
* @param {String} apiPath 本地API地址
* @param {String} target 目标代理服务器
*/
function newProxy(apiPath, target) {
let _sp = target.split("/");
let ctx = _sp[_sp.length - 1];
let pathRewrite = { [`^${apiPath}/`]: "/" };
let cookiePathRewrite = { ["/" + ctx]: apiPath };
return {
[apiPath + "/"]: {
target,
changeOrigin: true,
ws: true,
secure: false,
pathRewrite,
cookiePathRewrite
}
};
}
module.exports = { newProxy };