Static Websites
This handler provides an easy way to serve a static website such as a Hugo application to your clients.
Creating a Static Website
The following example will host the specified application available on http://localhost:8080/.
import org.genhttp.api.content.io.ResourceTree
import org.genhttp.engine.internal.Host
import org.genhttp.modules.io.fromDirectory
import org.genhttp.modules.practices.defaults
import org.genhttp.modules.staticwebsites.StaticWebsite
suspend fun main() {
val tree = ResourceTree.fromDirectory("/var/html/my-website")
val app = StaticWebsite.from(tree)
Host.create()
.defaults()
.handler(app)
.run()
}Requests to a directory (a path with a trailing slash, such as /blog/) are answered with the
index.html or index.htm file of this directory, all other files are served as they are.
To ship the website within your application, place it in src/main/resources/my-website and
read it from the classpath with ResourceTree.fromClasspath("my-website") - this works the same
whether the application runs from your IDE or a packaged JAR.