fixed panicing in web
This commit is contained in:
13
web/web.go
13
web/web.go
@@ -2,6 +2,7 @@ package web
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"embed"
|
"embed"
|
||||||
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -27,7 +28,15 @@ 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()
|
||||||
|
|
||||||
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)
|
||||||
})
|
})
|
||||||
@@ -40,11 +49,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(nil, "", 0),
|
ErrorLog: log.New(voidWriter, "", 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