1.3.0 • Published 4 years ago

microservice-proxy v1.3.0

Weekly downloads
1
License
Apache-2.0
Repository
github
Last release
4 years ago

Microservice Proxy

NPM version NPM downloads Build status Test coverage

Simple proxy for your microservices based on servie and path-to-regexp.

Installation

npm install microservice-proxy --save

Usage

Create the configuration:

{
  "rules": [
    {
      "path": "/login",
      "methods": ["get"],
      "url": "http://localhost:3001"
    },
    {
      "url": "http://localhost:3000"
    }
  ]
}

Start the proxy:

microservice-proxy -c config.json -p 9000

Or programmatically:

import { proxy } from "microservice-proxy";
import { createHandler } from "servie-http";
import { createServer } from "http";

const app = createHandler(
  proxy([
    {
      url: "http://example.com"
    }
  ])
);

createServer(app).listen(3000);

Background

Originally, this module was going to manage processes themselves and dynamically assign port numbers. Unfortunately, it's a little complex to manage the dependencies between the process ports (leaving this for another day). I found micro-proxy which is designed to do the same sort of thing, but it had a couple of issues - path matching and no HTTP/2 requests. I wrote this using ServieJS as an interesting case-study of how decoupling the request and response can lead to interesting mixups such as this (e.g. this could be deployed to AWS Lambda).

TypeScript

This project is written using TypeScript and publishes the definitions directly to NPM.

License

Apache 2.0