microservice-proxy
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

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

/microservice-proxy/

    Package Sidebar

    Install

    npm i microservice-proxy

    Weekly Downloads

    7

    Version

    1.3.0

    License

    Apache-2.0

    Unpacked Size

    28.1 kB

    Total Files

    12

    Last publish

    Collaborators

    • blakeembrey