Add trailing slash for routed directories (datarhei/restreamer#340)
In order for the UI to work properly with a relative %PUBLIC_URL% the route for the UI requires a / at the end. This commit is enforcing this. As a consequence, if the UI is behind a reverse proxy, it will still load properly.
This commit is contained in:
parent
9746248c10
commit
d7db9e4efe
1 changed files with 22 additions and 4 deletions
|
|
@ -338,13 +338,19 @@ func NewServer(config Config) (Server, error) {
|
||||||
s.router.Use(s.middleware.cors)
|
s.router.Use(s.middleware.cors)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.router.Use(middleware.RemoveTrailingSlashWithConfig(middleware.TrailingSlashConfig{
|
|
||||||
RedirectCode: 301,
|
|
||||||
}))
|
|
||||||
|
|
||||||
// Add static routes
|
// Add static routes
|
||||||
if path, target := config.Router.StaticRoute(); len(target) != 0 {
|
if path, target := config.Router.StaticRoute(); len(target) != 0 {
|
||||||
group := s.router.Group(path)
|
group := s.router.Group(path)
|
||||||
|
group.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{
|
||||||
|
Skipper: func(c echo.Context) bool {
|
||||||
|
if path == c.Request().URL.Path {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
RedirectCode: 301,
|
||||||
|
}))
|
||||||
group.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
group.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Skipper: middleware.DefaultSkipper,
|
Skipper: middleware.DefaultSkipper,
|
||||||
Root: target,
|
Root: target,
|
||||||
|
|
@ -359,6 +365,18 @@ func NewServer(config Config) (Server, error) {
|
||||||
|
|
||||||
for prefix, target := range config.Router.DirRoutes() {
|
for prefix, target := range config.Router.DirRoutes() {
|
||||||
group := s.router.Group(prefix)
|
group := s.router.Group(prefix)
|
||||||
|
group.Use(middleware.AddTrailingSlashWithConfig(middleware.TrailingSlashConfig{
|
||||||
|
Skipper: func(prefix string) func(c echo.Context) bool {
|
||||||
|
return func(c echo.Context) bool {
|
||||||
|
if prefix == c.Request().URL.Path {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}(prefix),
|
||||||
|
RedirectCode: 301,
|
||||||
|
}))
|
||||||
group.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
group.Use(middleware.StaticWithConfig(middleware.StaticConfig{
|
||||||
Skipper: middleware.DefaultSkipper,
|
Skipper: middleware.DefaultSkipper,
|
||||||
Root: target,
|
Root: target,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue