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

json-http-proxy

v1.0.0

Published

A json configuration based http proxy server

Downloads

11

Readme

Configurable Proxy Server

NPM Version NPM Downloads Build Status js-standard-style

An extensible proxy server which uses a basic JSON schema to configure all of its functionality. At its core, this is a wrapper around node-http-proxy and the Express router. The routing determines which upstreams any given request will be proxied to.

The original goal of this project was to run in development when working with microservices. So you can run all the services localy and use this proxy on port 80 to point different routes to your services. Since then I have expanded the functionality to be a simple to use "smart" proxy, which you can use to to a bunch of things, including:

  • Websocket proxying
  • CORS headers
  • Modifying request and response body data
  • User-agent detection/modification (Ex. serving mobile website views)
  • Cookie modifications
  • Cacheing proxy

All the functionality for doing this kind of processing is done through a simple plugin system. Plugins are just a function which are passed the instance of ProxyServer and the config options. They can use this instance to hook into events used to modify properties the requests, responses and other functionality. Even some core functionality is implemented as plugins, there are a few built in plugins for some common needs:

  • CORS: Properly sets the Access-Control-Allow-Methods and Access-Control-Allow-Origin headers based on the incoming request, also responds to OPTIONS requests.
  • Cookie modifier: Specify rules for modifying cookie names and values

Usage

$ npm install -g json-http-proxy
$ json-http-proxy

This will load the configuration file called proxy-config.json. Here is an example of this file:

{
	"routes": [
		{
			"path": "/api/users/*",
			"upstream": "api-users"
		},
		{
			"path": "/api/venues/*",
			"upstream": "api-venues"
		},
		{
			"path": "/api/broadcasts/*",
			"upstream": "api-broadcasts"
		},
		{
			"upstream": "client-website"
		}
	],
	"upstreams": {
		"client-website": {
			"port": 3000
		},
		"api-users": {
			"port": 3001
		},
		"api-venues": {
			"port": 3002
		},
		"api-broadcasts": {
			"port": 3003
		}
	}
}

This file is required in using node's require method, so anything that is valid to require can be used here, so this can be javascript. The above configuration file defined 4 upstream services which can be mapped to respond do different routes. The routing uses the Express router, so see their docs for how to specify paths or use the express route tester.

Options

  • address: the server address to listen on
  • port: port to open the server on
  • strict: passed to the router, enables strict routing
  • caseSensitive: passed to the router, enables case sensitive routing
  • changeOrigin: passed to http-proxy, enables origin changing in the proxy
  • xfwd: passed to http-proxy, enables x-forwarded-for headers in the proxy
  • headers: passed to http-proxy, sets headers to be passed to all upstreams
  • ssl: passed to http-proxy, sets ssl keys to use in an https server
  • timeout: passed to http-proxy as proxyTimeout
  • plugins: an object of plugins to initalize where the plugin name is the key
  • upstreams: an object of upstreams to register where the upstream name is the key
  • routes: an array of routes to handle