Legacy Migration

Runs on your machine

Replaces a legacy app step by step with a reverse proxy, redirects and new endpoints.

This sample runs on your machine only. It forwards requests to a legacy application running on your machine.

Clone GenHTTP, let Playground/Program.cs serve LegacyMigrationSample.Create() and start it with dotnet run - then try the commands below.

LegacyMigrationSample.cs47 lines
using GenHTTP.Api.Content;
using GenHTTP.Api.Protocol;

using GenHTTP.Modules.Functional;
using GenHTTP.Modules.IO;
using GenHTTP.Modules.Layouting;
using GenHTTP.Modules.Redirects;
using GenHTTP.Modules.ReverseProxy;

public static class LegacyMigrationSample
{

    public static IHandlerBuilder Create()
    {
        /*
         *
         * Replaces a legacy web application step by step: GenHTTP sits in front of
         * the old application and serves the parts that have already been rewritten.
         * Moved pages are redirected, everything else is still served by the legacy
         * application (expected to run on http://localhost:5000).
         *
         * See https://genhttp.org/documentation/content/handlers/reverse-proxy/
         * and https://genhttp.org/documentation/content/handlers/redirects/
         *
         */

        var newApi = Inline.Create()
                           .Get("status", () => new Status(true));

        var contact = Content.From(Resource.FromString("<h1>Contact us</h1>").Type(ContentType.TextHtml));

        var legacy = Proxy.Create()
                          .Upstream("http://localhost:5000/")
                          .ConnectTimeout(TimeSpan.FromSeconds(5))
                          .ReadTimeout(TimeSpan.FromSeconds(30));

        return Layout.Create()
                     .Add("api/v2", newApi) // GET http://localhost:8080/api/v2/status
                     .Add("contact", contact)
                     .Add("contact.php", Redirect.To("/contact")) // permanent, so search engines learn the new URL
                     .Add("shop", Redirect.To("https://shop.example.com/", temporary: true))
                     .Add(legacy); // everything else, e.g. GET http://localhost:8080/login.php
    }

    public record Status(bool Healthy);

}

Try it

With the sample running on your machine:

  1. Call the rewritten API

    curl -i http://localhost:8080/api/v2/status
  2. Open a page that has moved

    301 to the rewritten page

    curl -i http://localhost:8080/contact.php
  3. Open a page of the legacy app

    502, unless the legacy app runs on port 5000

    curl -i http://localhost:8080/login.php