/AD.ReverseProxy

Middleware to configure in-process reverse proxy servers for ASP.NET Core.

Primary LanguageC#MIT LicenseMIT

AD.ReverseProxy

The AD.ReverseProxy library provides middleware to configure an in-process reverse proxy server.

Current status

This project is experimental and not recommended for internet-facing servers at this time.

About

This project started to address a need to share a single port between several microservices.

While this is possible with the Http.Sys server, it is not supported by the Kestrel server without the use of a reverse proxy server such as IIS, Nginx, or Apache. This project aims to create a server-agnostic solution that would allow for a Kestrel-based reverse proxy.

Design goals

The primary goal of the project is to develop lightweight middleware that allows any in-process server to consider branching an incoming request to another server. Importantly, this branching should be configurable throughout run time.

An important secondary goal is to allow existing servers to incorporate this branching. That is, this middleware should not require its own server. Instead, an existing server should configure the middleware and then dispatch as required. If no viable alternative is registered with the middleware, the host continues down the HTTP request pipeline.

The middleware is designed to be flexible by allowing forward registration by the host, the initial recipient, or reverse registration by the client, the subsequent recipient. Registration from the client requires that the host be configured to accept client-based registration.

The middleware is also designed to allow for clients to be unregistered. This would support downtime-free microservice swapping. An updated microservice could be published, started, and registered with a host. Then the previous version can be unregistered. Until the server is unregistered, incoming requests will continue to the previous version as the targets are searched sequentially.

The middleware exposes endpoints for both forward registration and reverse registration. These endpoints correspond to requests from host-to-client and client-to-host, respectively.

Forward registration

Forward registration is configured from the /register-forward endpoint on the host. This forwards requests of a specific pattern from the host to the client server. The endpoint accepts a query parameter target which points to the client server.

Reverse registration

Reverse registration is configured from the /register-reverse endpoint on the client. This reverses the normal pattern and asks a host to forward requests of a specific pattern to the client server. The endpoint accepts a query parameter target which points to the host server.