Skip to content

Commit

Permalink
Switch back to chi for wildcard routing
Browse files Browse the repository at this point in the history
  • Loading branch information
kpurdon committed Dec 1, 2020
1 parent 4fb1315 commit 37c2c57
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cmd/iapap/iapap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"os"
"strings"

"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/kpurdon/iapap/pkg/iapap"
)

Expand All @@ -34,11 +36,14 @@ func main() {
log.Panicf("target %q is an invalid url: %s", target, err)
}

r := chi.NewRouter()
r.Use(middleware.Logger)

// provide healthcheck endpoints, use _* to avoid common whitelisted endpoints
http.HandleFunc("/_liveness", func(w http.ResponseWriter, r *http.Request) {
r.Get("/_liveness", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
})
http.HandleFunc("/_readiness", func(w http.ResponseWriter, r *http.Request) {
r.Get("/_readiness", func(w http.ResponseWriter, r *http.Request) {
// TODO: check if target is available
w.WriteHeader(http.StatusOK)
})
Expand All @@ -50,13 +55,13 @@ func main() {
if !strings.HasPrefix(e, "/") {
log.Panicf("whitelisted endpoint %q does not begin with a /", e)
}
http.Handle(e, proxy)
r.Handle(e, proxy)
}

// for all other endpoints, provide an authenticated proxy
http.Handle("/*", iapap.NewVerifier(audience).Apply(proxy))
r.Handle("/*", iapap.NewVerifier(audience).Apply(proxy))

addr := net.JoinHostPort("", port)
log.Printf("iapap listening on %s", addr)
log.Panic(http.ListenAndServe(addr, nil))
log.Panic(http.ListenAndServe(addr, r))
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ go 1.12

require (
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
github.com/go-chi/chi v1.5.0
github.com/stretchr/testify v1.6.1
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1/go.mod h1:+hnT3ywWDTAFrW5aE+u2Sa/wT555ZqwoCS+pk3p6ry4=
github.com/go-chi/chi v1.5.0 h1:2ZcJZozJ+rj6BA0c19ffBUGXEKAT/aOLOtQjD46vBRA=
github.com/go-chi/chi v1.5.0/go.mod h1:REp24E+25iKvxgeTfHmdUoL5x15kBiDBlnIl5bCwe2k=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down

0 comments on commit 37c2c57

Please sign in to comment.