Plugin Development Guide

Hiproxy supplied a mechanism of developing plugins. It’s simple that you need just develop a plugin and install it to global. Hiproxy should look for and load all plugins while it starts.

If you want to develop a plugin, hiproxy-plugin-example is a good demo which you can find at https://github.com/hiproxy/hiproxy-plugin-example. This is a entire plugin demo, you can start your own pluign base on the demo.

A plugin is a common npm module. You do not need to install hiproxy as a dependency.


Plugin’s architecture

Three condition should be satisfied before a module becomes a hiproxy pluign:

  1. It must be a standalone npm module which export only one object with three properties
1
2
3
4
5
6
7
8
9
10
module.exports = {
// CLI commands
commands: commands,
// Rewrite config redirectives
directives: directives,
// HTTP server routes
routes: routes
};
  • commands: <Array>, extends hiproxy CLI. Each element in the array should be a command configuration. See Command Configuration for details.

  • directives: <Array>, extends rewrite directive of hiproxy. Each element in the array should be a directive configuration. See Rewrite Directive for details.

  • routes: <Array>, extends page router of hiproxy. Each element in the array should be a route configuration.See Page Route Configuration for details.

  1. Plugin module must be installed to global

  2. Plugin name should use hiproxy-plugin- as prefix

Code Example

https://github.com/hiproxy/hiproxy-plugin-example/blob/master/index.js#L14-L23

Publish Plugin

You can publish a plugin into npm while it’s completed with development and testing.

The publish process is the same as publishing other npm module, since the a plugin of hiproxy is jsut a common npm module which follows given rules.

Hint

Hiproxy look for plugins which has hiproxy-plugiin- as prefix and installed in the directory described by npm root -g, so that hiproxy cannot find new developing pluigns.

npm link can create a symbol link of a plugin so that you can debug it while it’s in development. See npm link of npm document for details.