Add default page

The default page handler now also accepts / as URL path for the default
page.
This commit is contained in:
Felix Niederwanger 2023-11-25 23:05:40 +01:00
parent db10f0dc96
commit 9713b0d2c1
Signed by: phoenix
GPG key ID: 6E77A590E3F6D71C

View file

@ -101,11 +101,9 @@ func main() {
}
// Create default handlers
http.HandleFunc("/", createDefaultHandler())
http.HandleFunc("/health", createHealthHandler())
http.HandleFunc("/health.json", createHealthHandler())
http.HandleFunc("/index", createDefaultHandler())
http.HandleFunc("/index.htm", createDefaultHandler())
http.HandleFunc("/index.html", createDefaultHandler())
http.HandleFunc("/robots.txt", createRobotsHandler())
// Register hooks
@ -223,8 +221,16 @@ func createHealthHandler() Handler {
func createDefaultHandler() Handler {
return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
fmt.Fprintf(w, "weblug - webhook receiver program\nSee https://codeberg.org/grisu48/weblug\n")
if r.URL.Path == "/" || r.URL.Path == "/index.txt" {
w.WriteHeader(200)
fmt.Fprintf(w, "weblug - webhook receiver program\nhttps://codeberg.org/grisu48/weblug\n")
} else if r.URL.Path == "/index.htm" || r.URL.Path == "/index.html" {
w.WriteHeader(200)
fmt.Fprintf(w, "<!DOCTYPE html><html><head><title>weblug</title></head>\n<body><p><a href=\"https://codeberg.org/grisu48/weblug\">weblug</a> - webhook receiver program</p>\n</body></html>")
} else {
w.WriteHeader(404)
fmt.Fprintf(w, "not found\n")
}
}
}