Single Page Applications
Live on this serverHosts a single page application such as a React or Angular app.
Hosts a single page application, such as the build output of a React, Angular or Vue app. With
ServerSideRouting(), every path that is no file is answered with the index.html of the application, so
it can render routes such as /books/42 in the browser - even when they are opened directly or reloaded.
Put the build output of your application into a spa folder next to the program.
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/.
using GenHTTP.Engine.Internal;
using GenHTTP.Modules.IO;
using GenHTTP.Modules.Practices;
using GenHTTP.Modules.SinglePageApplications;
// GET /books/42 serves spa/index.html, the application renders the route in the browser
var app = SinglePageApplication.From(ResourceTree.FromDirectory("./spa"))
.ServerSideRouting();
await Host.Create()
.Handler(app)
.Defaults()
.RunAsync();
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.
Open the application
Open a client side route directly
The server delivers the application, which then renders the route.