koa-custom-proxy 用法
const Koa = ;const koaProxy = ; // http://127.0.0.1:3003/api/ip will be mapped to http://httpbin.org/ipconst proxyConfigs = matchPath: '/test/:proxyPath(.*)' options: // config for http-proxy proxyOptions: target: 'http://httpbin.org' changeOrigin: true // show logs or not logs: true // get url for dest server from current url { return '/' + match'proxyPath'; } const port = 3003;const app = ; app; proxyConfigs; app app;console;
依赖包
-
可以实现http, https, websocket格式的代理
-
将制定格式的url转为正则表达式
-
基于path-to-regexp的功能,获取url中每个关键字对应的的值
接口说明
- proxy(matchPath, options)
matchPath: 基于path-match格式的路径
options: {
proxyOptions, // node-http-proxy使用的参数
logs: true, // 是否展示日志
pathRewrite: // 将当前url路径映射到目标url路径
}