Skip to content

Commit 589f3a4

Browse files
committed
log redirects
1 parent 7979c54 commit 589f3a4

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,14 @@ func autocertListener() net.Listener {
5757
return listener
5858
}
5959

60+
func redirect(w http.ResponseWriter, r *http.Request) {
61+
url := fmt.Sprintf("https://%s/", r.Host)
62+
http.Redirect(w, r, url, http.StatusMovedPermanently)
63+
}
64+
6065
func redirect80() {
61-
err := http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
62-
url := fmt.Sprintf("https://%s/", r.Host)
63-
http.Redirect(w, r, url, http.StatusMovedPermanently)
64-
}))
66+
handler := chainMiddleware(http.HandlerFunc(redirect), logRequestMiddleware)
67+
err := http.ListenAndServe(":80", handler)
6568
if err != nil {
6669
fmt.Println(err)
6770
}

0 commit comments

Comments
 (0)