Browse Source

Actually honor the BasePath configuration.

What this requires is injecting the base path just before binding the
route via go-chi.

Unfortunately, this also causes a few issues with routergroups, because
the base path has to be injected as part of the routergroup path. I
suspect this isn't the correct way to do it, but it's been a while since
I dug into this part of the code.
template-theme-rewrite
Benjamin Shelton 7 months ago
parent
commit
89b03cf0b9
2 changed files with 3 additions and 3 deletions
  1. +2
    -1
      funcs.go
  2. +1
    -2
      routergroup.go

+ 2
- 1
funcs.go View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/http"
"path"
"strconv"
"strings"

@@ -29,7 +30,7 @@ func bindRoute(router *Router, route *Route) {
mux = router.Mux()
}

// Redirection path.
route.Path = path.Join(router.basePath, route.Path)
path := route.Path

if path == "/" {


+ 1
- 2
routergroup.go View File

@@ -40,7 +40,6 @@ func NewRouterGroup(path string, parent *Router) *RouterGroup {
router.group = rg
router.routes = rg.parent.routes
router.name = rg.name
router.basePath = pth.Join(parent.basePath, path)
router.renderer = rg.parent.renderer
router.afterResponse = make([]func(Context, error) error,
len(rg.parent.afterResponse))
@@ -51,7 +50,7 @@ func NewRouterGroup(path string, parent *Router) *RouterGroup {
copy(router.afterResponse, parent.afterResponse)
copy(router.beforeResponse, parent.beforeResponse)
rg.router = router
rg.basePath = path
rg.basePath = pth.Join(parent.basePath, path)

return rg
}


Loading…
Cancel
Save