Skip to content

Commit 03a17a2

Browse files
authored
fix(paths): remove trailing slash from requests (#7451)
This removes any ambiguity from how paths are handled, and at the same time it uniforms the ui paths with the other paths that don't have a trailing slash Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
1 parent 8ca98c9 commit 03a17a2

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

core/http/app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ func API(application *application.Application) (*echo.Echo, error) {
9090
// Middleware - StripPathPrefix must be registered early as it uses Rewrite which runs before routing
9191
e.Pre(httpMiddleware.StripPathPrefix())
9292

93+
e.Pre(middleware.RemoveTrailingSlash())
94+
9395
if application.ApplicationConfig().MachineTag != "" {
9496
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
9597
return func(c echo.Context) error {

core/http/routes/ui.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func RegisterUIRoutes(app *echo.Echo,
8989
})
9090

9191
// P2P
92-
app.GET("/p2p/", func(c echo.Context) error {
92+
app.GET("/p2p", func(c echo.Context) error {
9393
summary := map[string]interface{}{
9494
"Title": "LocalAI - P2P dashboard",
9595
"BaseURL": middleware.BaseURL(c),
@@ -115,7 +115,7 @@ func RegisterUIRoutes(app *echo.Echo,
115115
registerBackendGalleryRoutes(app, appConfig, galleryService, processingOps)
116116
}
117117

118-
app.GET("/talk/", func(c echo.Context) error {
118+
app.GET("/talk", func(c echo.Context) error {
119119
modelConfigs, _ := services.ListModels(cl, ml, config.NoFilterFn, services.SKIP_IF_CONFIGURED)
120120

121121
if len(modelConfigs) == 0 {
@@ -136,7 +136,7 @@ func RegisterUIRoutes(app *echo.Echo,
136136
return c.Render(200, "views/talk", summary)
137137
})
138138

139-
app.GET("/chat/", func(c echo.Context) error {
139+
app.GET("/chat", func(c echo.Context) error {
140140
modelConfigs := cl.GetAllModelsConfigs()
141141
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
142142

@@ -236,7 +236,7 @@ func RegisterUIRoutes(app *echo.Echo,
236236
return c.Render(200, "views/text2image", summary)
237237
})
238238

239-
app.GET("/text2image/", func(c echo.Context) error {
239+
app.GET("/text2image", func(c echo.Context) error {
240240
modelConfigs := cl.GetAllModelsConfigs()
241241
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
242242

@@ -286,7 +286,7 @@ func RegisterUIRoutes(app *echo.Echo,
286286
return c.Render(200, "views/tts", summary)
287287
})
288288

289-
app.GET("/tts/", func(c echo.Context) error {
289+
app.GET("/tts", func(c echo.Context) error {
290290
modelConfigs := cl.GetAllModelsConfigs()
291291
modelsWithoutConfig, _ := services.ListModels(cl, ml, config.NoFilterFn, services.LOOSE_ONLY)
292292

core/http/routes/ui_gallery.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ import (
99
)
1010

1111
func registerGalleryRoutes(app *echo.Echo, cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig, galleryService *services.GalleryService, opcache *services.OpCache) {
12-
13-
app.GET("/browse/", func(c echo.Context) error {
12+
app.GET("/browse", func(c echo.Context) error {
1413
summary := map[string]interface{}{
1514
"Title": "LocalAI - Models",
1615
"BaseURL": middleware.BaseURL(c),

0 commit comments

Comments
 (0)