Skip to content

Commit

Permalink
fix: use path instead of filepath to join http route paths
Browse files Browse the repository at this point in the history
Windows users were broken since #2292, as routes were registered with backslashes.
  • Loading branch information
zepatrik committed Apr 11, 2022
1 parent e505513 commit 16b1244
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions x/redir.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package x

import (
"net/http"
"path/filepath"
"path"
"strings"

"github.com/julienschmidt/httprouter"
Expand All @@ -18,7 +18,7 @@ func RedirectToAdminRoute(reg config.Provider) httprouter.Handle {
dest.Host = admin.Host
dest.Scheme = admin.Scheme
dest.Path = strings.TrimPrefix(dest.Path, AdminPrefix)
dest.Path = filepath.Join(admin.Path, AdminPrefix, dest.Path)
dest.Path = path.Join(admin.Path, AdminPrefix, dest.Path)

http.Redirect(w, r, dest.String(), http.StatusTemporaryRedirect)
}
Expand All @@ -32,7 +32,7 @@ func RedirectToPublicRoute(reg config.Provider) httprouter.Handle {
dest.Host = public.Host
dest.Scheme = public.Scheme
dest.Path = strings.TrimPrefix(dest.Path, AdminPrefix)
dest.Path = filepath.Join(public.Path, dest.Path)
dest.Path = path.Join(public.Path, dest.Path)

http.Redirect(w, r, dest.String(), http.StatusTemporaryRedirect)
}
Expand Down
42 changes: 21 additions & 21 deletions x/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package x

import (
"net/http"
"path/filepath"
"path"

"github.com/julienschmidt/httprouter"
)
Expand Down Expand Up @@ -63,42 +63,42 @@ func NewRouterAdmin() *RouterAdmin {
}
}

func (r *RouterAdmin) GET(path string, handle httprouter.Handle) {
r.Router.GET(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) GET(publicPath string, handle httprouter.Handle) {
r.Router.GET(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) HEAD(path string, handle httprouter.Handle) {
r.Router.HEAD(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) HEAD(publicPath string, handle httprouter.Handle) {
r.Router.HEAD(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) POST(path string, handle httprouter.Handle) {
r.Router.POST(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) POST(publicPath string, handle httprouter.Handle) {
r.Router.POST(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) PUT(path string, handle httprouter.Handle) {
r.Router.PUT(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) PUT(publicPath string, handle httprouter.Handle) {
r.Router.PUT(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) PATCH(path string, handle httprouter.Handle) {
r.Router.PATCH(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) PATCH(publicPath string, handle httprouter.Handle) {
r.Router.PATCH(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) DELETE(path string, handle httprouter.Handle) {
r.Router.DELETE(filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) DELETE(publicPath string, handle httprouter.Handle) {
r.Router.DELETE(path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) Handle(method, path string, handle httprouter.Handle) {
r.Router.Handle(method, filepath.Join(AdminPrefix, path), NoCacheHandle(handle))
func (r *RouterAdmin) Handle(method, publicPath string, handle httprouter.Handle) {
r.Router.Handle(method, path.Join(AdminPrefix, publicPath), NoCacheHandle(handle))
}

func (r *RouterAdmin) HandlerFunc(method, path string, handler http.HandlerFunc) {
r.Router.HandlerFunc(method, filepath.Join(AdminPrefix, path), NoCacheHandlerFunc(handler))
func (r *RouterAdmin) HandlerFunc(method, publicPath string, handler http.HandlerFunc) {
r.Router.HandlerFunc(method, path.Join(AdminPrefix, publicPath), NoCacheHandlerFunc(handler))
}

func (r *RouterAdmin) Handler(method, path string, handler http.Handler) {
r.Router.Handler(method, filepath.Join(AdminPrefix, path), NoCacheHandler(handler))
func (r *RouterAdmin) Handler(method, publicPath string, handler http.Handler) {
r.Router.Handler(method, path.Join(AdminPrefix, publicPath), NoCacheHandler(handler))
}

func (r *RouterAdmin) Lookup(method, path string) {
r.Router.Lookup(method, filepath.Join(AdminPrefix, path))
func (r *RouterAdmin) Lookup(method, publicPath string) {
r.Router.Lookup(method, path.Join(AdminPrefix, publicPath))
}

0 comments on commit 16b1244

Please sign in to comment.