Legacy Migration

Runs on your machine

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

Replaces an old web application step by step instead of all at once. GenHTTP runs in front of the legacy application: new endpoints and pages are served by GenHTTP, moved pages are redirected, and everything else is passed on to the legacy application by a reverse proxy.

The layout tries its own routes first, so /api/v2/ and /contact are new, /contact.php redirects permanently (search engines learn the new address), and any other path - such as /login.php - still reaches the legacy application on port 5000. Move one route at a time until the proxy can go.

Runs on your machine only. It forwards requests to a legacy application running on your machine.

To run it, create a console app (dotnet new console), add GenHTTP (dotnet add package GenHTTP.Full), replace Program.cs with the code below and start it with dotnet run - it answers at http://localhost:8080/.

Program.cs35 lines
using GenHTTP.Engine.Internal;

using GenHTTP.Api.Protocol;

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

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

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

// the legacy application, running on port 5000
var legacy = Proxy.Create()
                  .Upstream("http://localhost:5000/")
                  .ConnectTimeout(TimeSpan.FromSeconds(5))
                  .ReadTimeout(TimeSpan.FromSeconds(30));

var app = Layout.Create()
                .Add("api/v2", newApi) // GET /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 /login.php

await Host.Create()
          .Handler(app)
          .Defaults()
          .RunAsync();

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