Skip to content

Commit

Permalink
fix redirect, special healthz
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Jul 26, 2022
1 parent 3861153 commit 979937d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var (
pathRe = regexp.MustCompile(`^` + userRe + `\/` + repoRe + releaseRe + moveRe + `$`)
isTermRe = regexp.MustCompile(`(?i)^(curl|wget)\/`)
isHomebrewRe = regexp.MustCompile(`(?i)^homebrew`)
errMsgRe = regexp.MustCompile(`[^A-Za-z0-9\ :]`)
errMsgRe = regexp.MustCompile(`[^A-Za-z0-9\ :\/\.]`)
errNotFound = errors.New("not found")
)

Expand Down Expand Up @@ -64,8 +64,13 @@ type Handler struct {
}

func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == "/healthz" {
w.WriteHeader(http.StatusOK)
w.Write([]byte("OK"))
return
}
if r.URL.Path == "/" {
http.Redirect(w, r, "https:// github.com/jpillora/installer", http.StatusMovedPermanently)
http.Redirect(w, r, "https://github.com/jpillora/installer", http.StatusMovedPermanently)
return
}
// calculate reponse type
Expand Down
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net"
"net/http"
"strconv"
"time"

"github.com/jpillora/installer/handler"
"github.com/jpillora/opts"
Expand All @@ -25,6 +26,9 @@ func main() {
h := &handler.Handler{Config: c}
lh := requestlog.WrapWith(h, requestlog.Options{
TrustProxy: true, // assume will be run in paas
Filter: func(r *http.Request, code int, duration time.Duration, size int64) bool {
return r.URL.Path != "/healthz"
},
})
if err := http.Serve(l, lh); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit 979937d

Please sign in to comment.