Single Page Applications

Live on this server

Hosts a single page application such as a React or Angular app.

SinglePageApplicationSample.cs27 lines
using GenHTTP.Api.Content;

using GenHTTP.Modules.IO;
using GenHTTP.Modules.SinglePageApplications;

public static class SinglePageApplicationSample
{

    public static IHandlerBuilder Create()
    {
        /*
         *
         * Serves a single page application (SPA) from a directory (or resource tree in general).
         *
         * See https://genhttp.org/documentation/content/frameworks/single-page-applications/
         *
         */

        // shipped with this website (resources/samples/spa), use ResourceTree.FromDirectory("/var/app") to serve your build output
        var files = Resources.Tree("samples/spa");

        // GET /samples/spa/books/42 serves index.html, the route is rendered in the browser
        return SinglePageApplication.From(files)
                                    .ServerSideRouting();
    }

}

Try it

Send the requests to the sample running on this server - change the path, headers or body as you like, or copy them as curl commands.

  1. Open the application

    PAGE /samples/spa/ Open
  2. Open a client side route directly

    The server delivers the application, which then renders the route.

    PAGE /samples/spa/books/42 Open