/**
 * 创建一个服务代理
 * @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 };
  let proxy = {
    [apiPath + "/"]: {
      target,
      changeOrigin: true,
      ws: true,
      secure: false,
      pathRewrite,
      cookiePathRewrite
    }
  };
  return proxy;
}

module.exports = { newProxy };
