Files
gatus/controller/handler/spa.go
T

27 lines
770 B
Go
Raw Normal View History

2021-09-12 18:39:09 -04:00
package handler
2021-09-11 01:51:14 -04:00
import (
"html/template"
"log"
"net/http"
"github.com/TwiN/gatus/v3/config/ui"
2021-09-11 01:51:14 -04:00
)
func SinglePageApplication(staticFolder string, ui *ui.Config) http.HandlerFunc {
2021-09-11 01:51:14 -04:00
return func(writer http.ResponseWriter, request *http.Request) {
t, err := template.ParseFiles(staticFolder + "/index.html")
if err != nil {
2021-09-12 18:39:09 -04:00
log.Println("[handler][SinglePageApplication] Failed to parse template:", err.Error())
2021-09-11 01:51:14 -04:00
http.ServeFile(writer, request, staticFolder+"/index.html")
return
}
writer.Header().Set("Content-Type", "text/html")
err = t.Execute(writer, ui)
if err != nil {
2021-09-12 18:39:09 -04:00
log.Println("[handler][SinglePageApplication] Failed to parse template:", err.Error())
2021-09-11 01:51:14 -04:00
http.ServeFile(writer, request, staticFolder+"/index.html")
return
}
}
}