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

kor-proxy

v1.0.11

Published

promise proxy middleware for koa

Downloads

4

Readme

kor-proxy

promise proxy middleware for koa, support Load-Balance

Install

npm install kor-proxy

Aim

This middleware is supported do two things:

  1. Set Proxy Server Four options: (host [, protocol] [, auth] [, port])
  2. Rewrite the proxy request Header Match request will respond automatical internally use Stream.pipe.

Hello Kor-proxy

const Koa = require('neat-kor'); // router wrap for Koa
const proxy = require('kor-proxy');
const app = new Koa();

const ext = {
  timeout: 1000,
  headerRewrite() {
    // selected, deal req.headers before proxy;
  },
  dealTimeout() {
    // if none, will throw ('proxy-timeout');
  },
  rr: [options1, options2, ...] // every time merge one element to options
}

app.get('/proxy1', proxy('https://auth:[email protected]:8080', ext));

// the same as http(s).request 's options parameter
const options = {
  protocol: 'https', // defalut is http:
  auth: 'auth:pwd', // default is null
  host: 'test.url.com', // must pass!
  port: 8088, // defalut is 80(443)
};
app.get('/proxy2', proxy(options, ext));

Load-Balance

const Koa = require('neat-kor'); // router wrap for Koa
const proxy = require('kor-proxy');
const app = new Koa();

const rr = [{
    host: 'target.url.com1',
    port: 8000
  },
  {
    host: 'target.url.com2',
    port: 9000
  },
];

const ext = {
  timeout: 1000,
  headerRewrite() {
    // selected, deal req.headers before proxy;
  },
  dealTimeout() {
    // if none, will throw ('proxy-timeout');
  },
  rr// every time merge one element to options, except the same key.
}


// the same as http(s).request 's options parameter
const options = {
  port: 8088, // defalut is 80(443)
};
// Important: In this example, proxy server port will always be 8088, because options is prefer than rr's element.
app.get('/proxy2', proxy(options, ext));

API

proxy(options [, ext])

  • options(str | obj) - Default is {}.The absolute url path for proxy target, Eg: http(s)://auth:[email protected]:8080.It's used for getting protocol, auth, host, port properties, can also be defined explicitly in options.(Prefer than ext.rr's element.)Which will pass to http(s).request's options parameters. Eg: agent, headers..
  • ext (obj) - Default is {}.extension object.
  • ext.rr (Array) - : Default is undefined.Every element of arr will merge into options, in a round-robin manner. especially when need Load-Balance. (If rr's element have same key with options, it will not merge into, please put common key in options, dynamic for Load-Banlance put in rr )
  • ext.timeout (num) - Defalut is 15s, timeout(ms) between proxy request send and recieve response.
  • ext.headerRewrite (fn) - : Default is undefined, deal headers before proxy, recieve one param, the raw message.headers.
  • ext.dealTimeout (fn) - : Default is undefined, deal timeout error when proxy, if none will ctx.throw('proxy-timeout').
  • ext.client (fn) - : Default is undefined, Custom client, can created by neat-http, which kor-proxy is based.This method is set, ext.rr will be ignore(Because the client may be have rr configuration).

Error Handle

  • When catch Errors, will throw through ctx.throw(error.message), should deal in your koa app.