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