1 Star 0 Fork 0

否子戈 / easy-gateway

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

Easy-GateWay

A library to create proxy servers very easily.

Install

npm i -g easy-gateway

CLI

egw start --target=[target]

Params:

  • name: this server's name, should be unique, use current diranme as default
  • host: which ip to bind, 127.0.0.1 or 0.0.0.0 or others
  • port: which port to serve
  • target: which target to proxy to, give the target url
  • base: which dirs/files to serve up as static
  • token: if set, you should given token to access this server by queryString ?token=xxx
  • cookies: if set, the request to target will keep this cookie (original cookie as well)
  • headers: if set, http HEADER will be overrided
  • debug: if set, you can see the log in console
  • script: a js file to operate gateway

If you want to maintain this params, you can create a .egwrc file in your dir, and put this params in it, like:

## .egwrc
name=my-proxy-server
port=3000
target=https://www.google.com

And then, you will be able to not pass the params, only run egw start.

egw stop

Params:

  • name: the server to stop, use current dirname as default

API

The script param allow you to define your own gateway:

module.exports = function(args) {
  this.use({
    request(proxyReq, req, res) {},
  })
}

The function should return an instance of GateWay.

GateWay

const { GateWay } = require('easy-gateway')

module.exports = function() {
  const gateway = new GateWay()
  gateway.use({
    // ...
  })
  return gateway
}

You can use the following methods:

  • use(rule) add a new rule into gateway
  • clear() clear all rules
  • each(fn)

A rule is an object:

const rule = {
  async auth(req, res) {},
  request(req) {},
  response(res) {},
  async rewrite(req) {},
  async retarget(req) {},
  async serve(req, res) {},
}

read more

Comments ( 0 )

Sign in for post a comment

About

极其方便的nodejs代理转发网关 spread retract
NodeJS
MIT
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
NodeJS
1
https://gitee.com/frustigor/easy-gateway.git
git@gitee.com:frustigor/easy-gateway.git
frustigor
easy-gateway
easy-gateway
master

Search