mirror of
https://github.com/datarhei/core.git
synced 2025-12-24 13:07:56 +08:00
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:
@@ -338,13 +338,19 @@ func NewServer(config Config) (Server, error) {
|
||||
s.router.Use(s.middleware.cors)
|
||||
}
|
||||
|
||||
s.router.Use(middleware.RemoveTrailingSlashWithConfig(middleware.TrailingSlashConfig{
|
||||
RedirectCode: 301,
|
||||
}))
|
||||
|
||||
// Add static routes
|
||||
if path, target := config.Router.StaticRoute(); len(target) != 0 {
|
||||
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{
|
||||
Skipper: middleware.DefaultSkipper,
|
||||
Root: target,
|
||||
@@ -359,6 +365,18 @@ func NewServer(config Config) (Server, error) {
|
||||
|
||||
for prefix, target := range config.Router.DirRoutes() {
|
||||
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{
|
||||
Skipper: middleware.DefaultSkipper,
|
||||
Root: target,
|
||||
|
||||
Reference in New Issue
Block a user