2021-09-13 00:39:09 +02:00
|
|
|
package handler
|
2021-02-25 04:41:36 +01:00
|
|
|
|
2021-09-11 07:51:14 +02:00
|
|
|
import (
|
|
|
|
"html/template"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
2021-02-25 04:41:36 +01:00
|
|
|
|
2021-09-11 07:51:14 +02:00
|
|
|
"github.com/TwinProduction/gatus/config"
|
|
|
|
)
|
|
|
|
|
2021-09-13 00:39:09 +02:00
|
|
|
func SinglePageApplication(staticFolder string, ui *config.UIConfig) http.HandlerFunc {
|
2021-09-11 07:51:14 +02:00
|
|
|
return func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
t, err := template.ParseFiles(staticFolder + "/index.html")
|
|
|
|
if err != nil {
|
2021-09-13 00:39:09 +02:00
|
|
|
log.Println("[handler][SinglePageApplication] Failed to parse template:", err.Error())
|
2021-09-11 07:51:14 +02: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-13 00:39:09 +02:00
|
|
|
log.Println("[handler][SinglePageApplication] Failed to parse template:", err.Error())
|
2021-09-11 07:51:14 +02:00
|
|
|
http.ServeFile(writer, request, staticFolder+"/index.html")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2021-02-25 04:41:36 +01:00
|
|
|
}
|