npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

easy-gateway

v3.0.1

Published

easy gateway

Downloads

15

Readme

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