Static Websites
Live on this serverHosts a static website, with index.html support.
Serves a website made of HTML, CSS and image files, such as the output of a static site generator. A request
for a folder is answered with its index.html, so /about/ serves about/index.html.
Put your files into a website folder next to the program. ResourceTree.FromDirectory reads them from
there; files embedded into your assembly (ResourceTree.FromAssembly) work the same way.
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.StaticWebsites;
// GET / serves website/index.html, GET /about/ serves website/about/index.html
var app = StaticWebsite.From(ResourceTree.FromDirectory("./website"));
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 website