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-pipe-proxy

v0.0.9

Published

http pipe proxy

Downloads

5

Readme

easy-pipe-proxy

  • easy-pipe-proxy is a HTTP transparent proxy middleware, the goal of easy-pipe-proxy is to solve the browser cross-domain request.
  • It is based on high performance of node.js native HTTP pipe

###install

npm install easy-pipe-proxy

example

connect or express

proxy layer

proxy.js

var app    = require('connect')();
var epp    = require('easy-pipe-proxy');

var proxyConfig = {
  host:'localhost',
  port:'3007',
  timeout:1000,
  router:'/api'
}

var proxy = new epp(proxyConfig);
//var proxy2 = new epp(proxyConfig2);

/*
	All requests from the client which req.url start withs '/api',will pipe proxy to 
	host: localhost, port:3007. 
*/

app.use(proxyConfig.router,proxy.pipe())

//app.use(proxyConfig2.router,proxy2.pipe())

app.use(function (err,req,res,next) {

  // err.eppRouter help you distinguish which proxy occurs error
  // if err.eppRouter or err.eppCode is undefined , 
  // it means nothing error occurs in easy-pipe-proxy
  
  console.log(err.code,err.eppCode,err.eppRouter);
  if (err.eppCode) {
  	// error occur in easy-pipe-proxy
	res.statusCode = err.eppCode
  	res.end(err.message);  	
  }
  
  // other errors
  //...
})

app.listen(3006);

back-end service layer

service.js

var app    = require('connect')();
/*
	if A HTTP request from client is 'localhost:3006/api/ok' via any
	method (GET/POST),
	easy-pipe-proxy will auto pipe this request to 'localhost:3007/ok',and then pipe
	the proxy response to client;
*/

app.use('/ok',(req,res,next) => {
  res.statusCode = 200;
  res.end('hello world');
})

/*
	if A HTTP request from client is 'localhost:3006/api/pending' via any
	method (GET/POST),
	easy-pipe-proxy will auto pipe this request to 'localhost:3007/pending',and then pipe
	the proxy response to client;
*/

app.use('/pending',(req,res,next) => {

})

app.listen(3007);

start example

node proxy.js
node service.js

vist http://localhost:3006/api/ok

In this example, http://localhost:3007/ok and http://localhost:3006/api/ok will get the same result.

proxyConfig

  • host [string]: The back-end service IP or domian
  • port [string/number]: The back-end service port
  • timeout [number]: default 2 min. pipe-proxy will abort proxy after timeout (mses),and it will cause a timeout error.
  • router [string]: connect's/express's router, this router controls requests which come from the client will be proxy by easy-pipe-proxy.

errorCode

if some error occurs in easy-pipe-proxy, 
easy-pipe-proxy will append eppCode (easy-pipe-proxy Code) and eppRouter (easy-pipe-proxy Router) to the error object . 
Connect/express error middleware will capture this error object.  

like:
  vist http://localhost:3006/api/pending
  
  app.use(function (err,req,res,next) {
    console.log(err.eppCode,err.eppRouter);
  })

but if nothing error occurs in easy-pipe-proxy ,the eppCode and eppRouter attribute will be undefined.
  

eppCode

  • 408, proxy timeout
  • 500, proxy error

eppRouter

  • config.router, eg: '/api', config.router

proxy header

  • in order to solve some security problems, easy-pipe-proxy will change req.headers.host (which comes from client ) to config.host + ':' + config.port

  • eg: if we pipe proxy xxx.xxx.xxx.xxx:3006 to xxx.xxx.xxx.xxx:3007 , and then we vist http://xxx.xxx.xxx.xxx:3006 in browser. easy-pipe-proxy receives req.headers.host from client should be 'xxx.xxx.xxx.xxx:3006' , easy-pipe-proxy will change req.headers.host to 'xxx.xxx.xxx.xxx:3007' and save 'xxx.xxx.xxx.xxx:3006' to 'X-Proxy-Host' as a property of req.headers

code:

	req.headers['X-Proxy-Host'] = req.headers.host;
	req.headers.host = config.host ;
	
	...
	
	if (config.port) {
      option.port = config.port;
      req.headers.host =  config.host + ':' + config.port;
    }