Détail du package

hiproxy

hiproxy715MIT1.3.3

hiproxy - lightweight and powerful proxy tool for front-end developer based on Node.js.

nodejs, proxy, nginx, reverse-proxy

readme

hiproxy

hiproxy

hiproxy is a lightweight web proxy tool based on Node.js. The primary purpose of hiproxy is to solve the problem of host management and reverse proxy needs of developers.

For example, if you are working as a team and each of the developers in the team need a different proxy setting, you will no longer need to modify your hosts file or use a web server like Nginx as a reverse proxy.

hiproxy extends the syntax of hosts file to support port numbers. Besides, hiproxy also supports configuration through a syntax similar to the Nginx configuration file.

中文版文档

Build Status Build status codecov js-semistandard-style npm Node.js version license

Why Hiproxy?

If you are a front-end developer, it is not uncommon for you to encounter the following problems:

Debugging web pages locally: To develop your web projects in a local development environment, you’ll have to run a back-end server (such as a Node.js express application, or a Java SpringBoot application). As a front-end developer, you might not be familiar with the back-end technology stack, simply setting up the development environment can consume a lot of your time.

Cross-Origin Issues: While developing your front-end projects locally, you might need to solve cross-domain and cross-origin resource sharing issues. To address these problems, you will need to modify the response header.

Self-Signed Certificates: You’ll often need to test https pages. When you visit https pages with a self-signed certificate, your browser will raise security warnings.

One common way to modify the response header is to put a proxy as a “man in the middle”. NGINX, for example, has a nice syntax that you can configure as a reverse-proxy to handle all these needs.

Although NGINX is a great tool to address all the above problems, when setting up NGINX, you’ll also modify your hosts file a lot to proxy the requests to a local NGINX service. This can especially turn out to be a burden if you are working on multiple projects.

Can we have a better way to solve this problem?

Well, yes. Meet hiproxy!

Features

  • Nginx.config-style configuration file syntax with a simple and intuitive configuration
  • Extended hosts configuration with port numbers.
  • Plugin extensions to rewrite directives, command line interface, and pages
  • Automatic generation and management of TLS certificates
  • Auto-detection of configuration file
  • Proxy auto-configuration
  • You can run hiproxy as a background service and redirect its output to a log file.
  • You can open a browser window and configure your proxy from its web interface.
  • hiproxy provides a Node.js API for fine-tuning and lower-level control.

Installation

npm install -g hiproxy

If you want to experience the latest features of hiproxy, you can install the next version.

npm install -g hiproxy@next

Usage

CLI

Start proxy server:

hiproxy start -p 5525 --debug --workspace ${PATH_TO_WORKSPACE}

Configure proxy:

127.0.0.1:5525

CLI Usage

> hiproxy --help

Usage:

    hiproxy [command] [option]

Commands:

  start    Start a local proxy server
  stop     Stop the local proxy server (Only works in daemon mode)
  restart  Restart the local proxy service (Only works in daemon mode)
  state    Show all the servers state (Only works in daemon mode)
  open     Open browser and set proxy
  hello    A test command that say hello to you.

Options:

  -v, --version     Display version information
  -h, --help        Display help information
  --log-dir <dir>   The log directory when run in background, default: user home directory
  --log-time        Show time info before every log message
  --log-level       The log levels, format: <level1>[,<lavel2[,...]]
  --grep <content>  Filter the log data

Documentation

Note: This is an incomplete documentation, we are still writing, if you are willing to help us write or translate the documentation, please contact zdying@live.com

Steps for Contributing Documentation

  • The documentation repo is : https://github.com/hiproxy/documentation

  • Choose one of the issues and submit a comment that tell others you will translate this part.

  • Create your own fork on github.

  • Translate the md files that you choose, you can reaplce the file content to the English version directly.

  • Submit a PR.

After you have submitted your pull request, we'll try to get back to you as soon as possible. We may suggest some changes or improvements.

Wiki

Node.js API

var Server = require('hiproxy').Server;
var proxy = new Server(8848, 10086);

// events
proxy.on('request', function(req, res){
  req.someThing = 'some thing';
  console.log('new request =>', req.method, req.url);
});

proxy.on('data', function(data){
  console.log('on response =>', data.toString());
});

proxy.start().then(function (servers) {
  console.log('proxy server started at: 127.0.0.1:8848');
});

// stop proxy server
// proxy.stop();

// restart proxy server
// proxy.restart();

Hosts Configuration Example

hiproxy supports enhanced version of hosts, the hosts file supports not only IP but also port numbers.

# comment
127.0.0.1 example.com
127.0.0.1:8800 blog.example.com life.example.com

Rewrite Configuration Example

set $port 8899;
set $ip   127.0.0.1;
set $online 210.0.0.0;

domain example.com {
  location / {
    proxy_pass http://$online/;
  }

  location /blog/ {
    proxy_pass http://$ip:$port/blog/;

    proxy_set_header from 'hiproxy';

    set_header proxy 'hiproxy';
  }
}

Sample Project

Here is an example project that you can play with.

Running Tests

npm test

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Authors

  • zdying - HTML/JavaScript/CSS/Node.js developer zdying
  • zhouhailong - HTML/JavaScript/CSS/Node.js developer zhouhailong
  • Alfred Sang (aka i5ting) - a full-stack developer and Node.js evangelist. He works for Alibaba Group as a Principal Front-End Developer and runs a self-media on the topic of Full-stack Node.js. His book “The Marvelous Node.js” (Part I) was published in July 2019.._

See also the list of contributors who participated in this project.

Built With

  • hemsl - a lightweight Node.js command line argv parser and command executor.
  • colors - get color and style in your node.js console.
  • node-forge - JavaScript implementations of network transports, cryptography, ciphers, PKI, message digests, and various utilities.
  • op-browser - Open browser window and set proxy.
  • os-homedir - Node.js 4 os.homedir() ponyfill.
  • url-pattern - easier than regex string matching patterns for urls and other strings. turn strings into data or data into strings.
  • simple-mime - A simple mime database.

Thanks to the authors of the above libraries to provide such a useful library.

Thanks To

Thanks to the above friends to help translate hiproxy documents.

Change Log

See the CHANGELOG.md for details.

License

This project is licensed under the MIT License - see the LICENSE file for details

Code of Conduct

We are committed to making participation in this project a harassment-free experience for everyone, regardless of the level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.

See the code of conduct for details.

changelog

Change Log

[2.0.0] - 2019-08-??

上次更新到现在已经很长时间了.对不起,我迟到了。

hiproxy 2.0版本更新了很多功能细节,修复了很多问题,对代码进行了重构,重新规划、编写了自动化测试用例,也更新了一部分文档。

这需要耗费相对较多的时间,除了写代码,我业余时间还需要拍一些照片,这是我新的爱好!

hiproxy现在基本功能已经算是稳定,但是hiproxy还能做很多事情,需要继续优化的也还有很多。希望喜爱hiproxy的人能一起参与,为hiproxy做出一些贡献。

如果你愿意为hiproxy贡献一份自己的力量,请提出你的issue。

It has been a long time since the last update. Sorry, I am late.

The hiproxy 2.0 version updates a lot of feature details, fixes a lot of problems, refactors the code, re-plans, writes automated test cases, and updates some of the documentation.

This takes a relatively long time. In addition to writing code, I still need to take some photos in my spare time. This is my new hobby!

Hiproxy is now basically stable, but hiproxy can do a lot of things, and there are still many things that need to be optimized. I hope that people who love hiproxy can participate and contribute to hiproxy.

If you are willing to contribute a power to hiproxy, please submit your issue.

Added

  • Support multiple hiproxy certificates for the same device, see #57.
  • Support plugins installed by yarn, see #53 增加yarn全局插件检测.
  • Support onError() callback.
  • Support onBeforeRequest() callback.
  • Support onData() callback.
  • Support onBeforeResponse() callback;
  • Add addCallback() api for hiproxy.
  • Ignore duplicate hosts rules(TODO ? keep this or remove it? #b3d0a3bfa9c47565e9ab37e5ba1fcaf247fe546e).
  • Add default Host header.
  • The send_file directive now send Content-Type header.
  • The proxy_append_body directive now will auto detect JSON and form data.
  • The proxy_replace_body directive now support flag igm.
  • Add new directive proxy_timeout timeout.
  • Add direcitive sub_filter_last_modified on|off.
  • Add directive sub_filter_types types.
  • Add directive sub_filter_once on|off.
  • hiproxy home page use https://hi.proxy/.

Fixed

  • Fix #59 haeder设置重复.
  • Fix: Empty rewrite file error when starting hiproxy.
  • Fix: hosts domain https request error.
  • Fix: content by echo directive has no proxy log.
  • Fix: hiproxy home page charset.
  • Fix: file upload and Non-text file damaged.
  • Fix: windows 7 hosts parse error.

Updated

  • Update hiproxy log prefix label.
  • CLI add --error/--warn/--detail/--debug opts, and remove --log-level opt.
  • Update event params format, user object instead.
  • res.headers now can get values setted by res.setHeader().
  • The validity period of the certificate is changed from 1 year to 5 years.

[1.3.1] - 2018-03-26

Fixed

[1.3.0] - 2018-03-15

Added

[1.2.13] - 2018-03-14

Added

  • Support for automatic selection of available port numbers when creating services. See API for more details.
  • Add more test case.

[1.2.12] - 2018-02-26

Added

  • Add requestend event.
  • Add requestId and _startTime for CONNECT request.
  • Start HTTPS service by default.

[1.2.11] - 2018-01-09

Added

  • Auto find config file from current dir.
  • Add current config files log.

[1.2.10] - 2017-12-21

Bugfix

  • fix(command/start): can't found cli.js module on daemon mode #43

Thanks to raccoon-lee

[1.2.9] - 2017-11-08

Bugfix

  • Fixbug: window下无法创建名为*.xx.xx的证书 #40

[1.2.8] - 2017-10-30

Bugfix

  • Fix plugin name for windows.

[1.2.7] - 2017-10-24

Added

  • New hiproxy home page 🍺🍺🍺 👏👏👏

[1.2.6] - 2017-10-19

Bugfix

  • Fix hosts proxy log error

Added

  • Directive can return promise or non-promise value now
  • Add clearFiles() api for hiproxyServer.hosts and hiproxyServer.rewrite
  • Add addRule() api for hiproxy server instance
  • Support custom hosts and rewrite snippets
  • Add hiproxy global variable
  • Add dataProvider module for plugins

Updated

  • change proxy log format

[1.2.5] - 2017-10-10

Bugfix

  • Fix alias directive proxy log
  • Change some log color from 'blue' to 'cyan'

Added

  • Domain block support multiple domain

[1.2.4] - 2017-10-09

Bugfix

  • Fix error on windows
  • Fix sub-command tips in help info

[1.2.3] - 2017-09-21

Added

  • Add requestId for each request
  • Show doc site url in hiproxy cmd and show new issue url in error msg

Bugfix

  • Response data event not emitted when use gzip

[1.2.2] - 2017-09-18

Added

  • Change Hiproxy_Custom_CA_Certificate ext from pem to crt
  • Add sub-command tips in help info

Bugfix

  • Plugins load error message has undefined

[1.2.1] - 2017-09-12

Added

  • add hiproxy init CLI command
  • Use Hiproxy Custom CA root certificate to issue localhost certificate

Bugfix

  • send_file directive bug

[1.2.0] - 2017-09-04

Added

  • Regular expressions can omit the first / and last /
  • Update proxy log format
  • Use a more powerful syntax parser, and support main syntax error hints

[1.1.9] - 2017-08-07

Added

  • Add built-in variable $base_name and $dir_name
  • Add built-in API enableConfFile and disableConfFile

Bugfix

  • Response 404 when use alias and the request has query string.