In this section, we will start by adding an index.html
and wiring our server to server static content.
We want a tracer bullet to for our web client.
This will get the process of generating and serving
our web UI in place. We will then add in more complexity
for resources and js to get, set, and display data.
(explain tracer bullet more)
(add link to webpage about it)
Generator
We are going to add an index.html file, so first
we make sure it will be generated from a template.
We update our server generator to add index.html
to the OnceFiles.
In order to serve our HTML, we need
to adjust our API routes.
First we need to move our existing routes to /api,
to make room for our static content route
Second, we need to server our static content from /
so index.html behaves correctly in the browser.
templates/router.go
funcsetupRouter(e *echo.Echo) error {
// Internal routes and Prometheus
// Static content
e.Static("/", "client")
// API routes
g := e.Group("/api")
// routes and resources
returnnil
}