fixed panicing in web

This commit is contained in:
2024-04-14 17:58:59 +02:00
parent 31dbba4d40
commit b50eaad328

View File

@@ -2,6 +2,7 @@ package web
import (
"embed"
"io"
"log"
"net/http"
"text/template"
@@ -27,7 +28,15 @@ func handleHTML(w http.ResponseWriter, embed embed.FS, path string) {
tmpl.Execute(w, nil)
}
func recoverFromPanic() {
if r := recover(); r != nil {
logrus.Errorf("Recovered from panic: %v", r)
}
}
func HostRoutes(botID string) {
defer recoverFromPanic()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, custom.Gh_url, http.StatusMovedPermanently)
})
@@ -40,11 +49,11 @@ func HostRoutes(botID string) {
http.HandleFunc("/tos", func(w http.ResponseWriter, r *http.Request) {
handleHTML(w, tosHTML, "./html/tos.html")
})
var voidWriter io.Writer
server := &http.Server{
Addr: ":443",
Handler: nil,
ErrorLog: log.New(nil, "", 0),
ErrorLog: log.New(voidWriter, "", 0),
}
logrus.Info("Starting server for html routes on :443...")
if err := server.ListenAndServeTLS("./web/cert.pem", "./web/key.pem"); err != nil {