3.0.1 • Published 1 year ago

easy-gateway v3.0.1

Weekly downloads
4
License
MIT
Repository
github
Last release
1 year ago

Easy-GateWay

A library to create proxy servers very easily.

Install

npm i -g easy-gateway

CLI

egw start --target=[target]

Params:

  • name: optional, when set, it will be deamon server's name, should be unique, if not set, just run in cli
  • host: which ip to bind, 127.0.0.1 or 0.0.0.0 (default) or others
  • port: which port to expose (default random between 10000 and 20000)
  • target: which target url to proxy to
  • base: which dirs/files to serve up as static content base
  • token: if set, you should given token to access this server
  • proxy: if set, the rules will be used as proxy, i.e. /api->http://localhost:9999/api;;/doc->/docs, notice use -> to point source and target
  • proxyHeaders: if set, http request HEADERS send by proxier will be set
  • proxyCookies: if set, the request to target will keep this cookie (original cookie as well)
  • headers: if set, http response HEADERS will be set
  • script: a js file to operate gateway
  • secure: enable https
  • cors: enable CORS
  • debug: if set, you can see the log in console

The token is special, when you pass token, your target site will be must visited with a auth token. token can also be {token_key}:{token_value} to match ?{token_key}={token_value}. You can visit with 1/ query string ?{token_key}={token_value}, 2/ cookie {token_key}={token_value}, 3/ http headers "{token_key}": "{token_value}". {token_key} is default if not passed as token when use query string, as EGW-TOKEN-{PORT} when use cookie, as EGW-TOKEN when use headers. When you visit visit with query string, cookie will be set too, so you can visit again without query string with cookie.

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. Notice that, only when you give name, egw start will run in domean.

egw stop

Params:

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

Setup domean all .egwrc files which contain name in .egwrc directory.

egw off

Down all .egwrc files which contain name in .egwrc directory.

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

2.2.1

1 year ago

2.2.0

1 year ago

3.0.1

1 year ago

3.0.0

1 year ago

2.1.12

1 year ago

2.1.13

1 year ago

2.1.10

1 year ago

2.1.11

1 year ago

2.1.9

2 years ago

2.1.4

3 years ago

2.1.6

3 years ago

2.1.5

3 years ago

2.1.8

3 years ago

2.1.7

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.3

3 years ago

2.1.0

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.25

4 years ago

0.0.22

4 years ago

0.0.20

4 years ago

0.0.21

4 years ago

0.0.19

4 years ago

0.0.17

4 years ago

0.0.18

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.4

4 years ago

0.0.1

4 years ago