@leizm/http-proxy
Awsome HTTP proxy, configurable and flexible 一个简单灵活的 HTTP 代理服务器
Last updated a year ago by leizongmin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @leizm/http-proxy 
SYNC missed versions from official npm registry.

@leizm/http-proxy

一个简单灵活的 HTTP 代理服务器

命令行工具

安装

npm i @leizm/http-proxy -g

使用方法

首先新建代理配置文件 proxy.yaml:

# 代理服务器监听地址
host: 0.0.0.0

# 代理服务器端口
port: 4567

# 是否显示调试信息
debug: false

# 代理规则
rules:
- match: http://morning.work/(.*)
  proxy: http://ucdok.com/{1}
  headers:
    host: jsxss.com
- match: http://*.qq.com/(.*)
  proxy: https://www.so.com/s?ie=utf-8&fr=so.com&src=home_so.com&q={1}
- match: http://example.com
  proxy: /site/example.com

然后执行 start 命令启动:

http-proxy start proxy.yaml

说明:配置文件修改后,会自动重载配置

配置规则说明

  • match 参数使用 path-to-regexp 模块解析,可以使用通配符 * 或者 :name 来命名模糊匹配部分,或者使用用正则表达式
  • proxy 参数内可以使用 {name} 来代替匹配到的可变部分
  • headers 参数可用于指定一些自定义的相应头

作为模块使用

安装

npm install @leizm/http-proxy --save

使用方法

import HTTPProxy from '@leizm/http-proxy';

const proxy = new HTTPProxy();

proxy.addRule({
  match: 'http://morning.work/(.*)',
  proxy: 'http://ucdok.com/{1}',
  headers: {
    host: 'jsxss.com',
  },
});

proxy.server.listen(4567, () => console.log('listening...'));

License

MIT License

Copyright (c) 2017-2018 Zongmin Lei <leizongmin@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Current Tags

  • 1.0.1                                ...           latest (a year ago)

2 Versions

  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (16)
Dev Dependencies (3)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |