Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/serviejs/microservice-proxy
Simple proxy for your microservices based on servie and path-to-regexp
https://github.com/serviejs/microservice-proxy
microservice proxy servie
Last synced: 8 days ago
JSON representation
Simple proxy for your microservices based on servie and path-to-regexp
- Host: GitHub
- URL: https://github.com/serviejs/microservice-proxy
- Owner: serviejs
- License: other
- Created: 2018-10-22T02:34:36.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-10T02:59:49.000Z (about 3 years ago)
- Last Synced: 2024-12-14T11:38:22.049Z (21 days ago)
- Topics: microservice, proxy, servie
- Language: TypeScript
- Size: 776 KB
- Stars: 8
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Microservice Proxy
[![NPM version](https://img.shields.io/npm/v/microservice-proxy.svg?style=flat)](https://npmjs.org/package/microservice-proxy)
[![NPM downloads](https://img.shields.io/npm/dm/microservice-proxy.svg?style=flat)](https://npmjs.org/package/microservice-proxy)
[![Build status](https://img.shields.io/travis/serviejs/microservice-proxy.svg?style=flat)](https://travis-ci.org/serviejs/microservice-proxy)
[![Test coverage](https://img.shields.io/coveralls/serviejs/microservice-proxy.svg?style=flat)](https://coveralls.io/r/serviejs/microservice-proxy?branch=master)> Simple proxy for your microservices based on [`servie`](https://github.com/serviejs/servie) and [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp).
## Installation
```
npm install microservice-proxy --save
```## Usage
Create the configuration:
```json
{
"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:
```js
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`](https://github.com/zeit/micro-proxy) which is designed to do the same sort of thing, but it had a couple of issues - [path matching](https://github.com/zeit/micro-proxy/pull/35) 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](https://github.com/Microsoft/TypeScript) and publishes the definitions directly to NPM.
## License
Apache 2.0