Skip to content

Commit

Permalink
deal with non-slash ending docs urls
Browse files Browse the repository at this point in the history
  • Loading branch information
nicpottier committed May 10, 2019
1 parent cad068a commit 0245081
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 10 additions & 2 deletions web/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,16 @@ import (
var docServer http.Handler

func init() {
docServer = http.StripPrefix("/docs/", http.FileServer(http.Dir("docs")))
web.RegisterRoute(http.MethodGet, "/docs*", handleDocs)
docServer = http.StripPrefix("/mr/docs", http.FileServer(http.Dir("docs")))

// redirect non slashed docs to slashed version so relative URLs work
web.RegisterRoute(http.MethodGet, "/mr/docs", func(ctx context.Context, s *web.Server, r *http.Request, rawW http.ResponseWriter) error {
http.Redirect(rawW, r, "/mr/docs/", 301)
return nil
})

// all slashed docs are served by our static dir
web.RegisterRoute(http.MethodGet, "/mr/docs/*", handleDocs)
}

func handleDocs(ctx context.Context, s *web.Server, r *http.Request, rawW http.ResponseWriter) error {
Expand Down
1 change: 0 additions & 1 deletion web/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func NewServer(ctx context.Context, config *config.Config, db *sqlx.DB, rp *redi

// set up our middlewares
router.Use(middleware.DefaultCompress)
router.Use(middleware.StripSlashes)
router.Use(middleware.RequestID)
router.Use(middleware.RealIP)
router.Use(panicRecovery)
Expand Down

0 comments on commit 0245081

Please sign in to comment.