gatus/controller/spa.go

28 lines
756 B
Go
Raw Normal View History

package controller
2021-09-11 07:51:14 +02:00
import (
"html/template"
"log"
"net/http"
2021-09-11 07:51:14 +02:00
"github.com/TwinProduction/gatus/config"
)
func spaHandler(staticFolder string, ui *config.UIConfig) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
t, err := template.ParseFiles(staticFolder + "/index.html")
if err != nil {
log.Println("[controller][spaHandler] Failed to parse template:", err.Error())
http.ServeFile(writer, request, staticFolder+"/index.html")
return
}
writer.Header().Set("Content-Type", "text/html")
err = t.Execute(writer, ui)
if err != nil {
log.Println("[controller][spaHandler] Failed to parse template:", err.Error())
http.ServeFile(writer, request, staticFolder+"/index.html")
return
}
}
}