Files
gatus/controller/handler/spa.go
T

31 lines
1.3 KiB
Go
Raw Normal View History

2021-09-12 18:39:09 -04:00
package handler
2021-09-11 01:51:14 -04:00
import (
_ "embed"
2021-09-11 01:51:14 -04:00
"html/template"
"log"
"net/http"
2022-06-20 21:25:14 -04:00
"github.com/TwiN/gatus/v4/config/ui"
"github.com/TwiN/gatus/v4/web"
2021-09-11 01:51:14 -04:00
)
func SinglePageApplication(ui *ui.Config) http.HandlerFunc {
2021-09-11 01:51:14 -04:00
return func(writer http.ResponseWriter, request *http.Request) {
t, err := template.ParseFS(static.FileSystem, static.IndexPath)
2021-09-11 01:51:14 -04:00
if err != nil {
// This should never happen, because ui.ValidateAndSetDefaults validates that the template works.
log.Println("[handler][SinglePageApplication] Failed to parse template. This should never happen, because the template is validated on start. Error:", err.Error())
http.Error(writer, "Failed to parse template. This should never happen, because the template is validated on start.", http.StatusInternalServerError)
2021-09-11 01:51:14 -04:00
return
}
writer.Header().Set("Content-Type", "text/html")
err = t.Execute(writer, ui)
if err != nil {
// This should never happen, because ui.ValidateAndSetDefaults validates that the template works.
log.Println("[handler][SinglePageApplication] Failed to execute template. This should never happen, because the template is validated on start. Error:", err.Error())
http.Error(writer, "Failed to execute template. This should never happen, because the template is validated on start.", http.StatusInternalServerError)
2021-09-11 01:51:14 -04:00
return
}
}
}