diff --git a/web/apps/apps.go b/web/apps/apps.go index c3db5b6cd46..5af909e9938 100644 --- a/web/apps/apps.go +++ b/web/apps/apps.go @@ -803,7 +803,7 @@ func openWebapp(c echo.Context) error { // WebappsRoutes sets the routing for the web apps service func WebappsRoutes(router *echo.Group) { - router.GET("/", listWebappsHandler) + router.GET("", listWebappsHandler) router.GET("/:slug", getHandler(consts.WebappType)) router.POST("/:slug", installHandler(consts.WebappType)) router.PUT("/:slug", updateHandler(consts.WebappType)) @@ -818,7 +818,7 @@ func WebappsRoutes(router *echo.Group) { // KonnectorRoutes sets the routing for the konnectors service func KonnectorRoutes(router *echo.Group) { - router.GET("/", listKonnectorsHandler) + router.GET("", listKonnectorsHandler) router.GET("/:slug", getHandler(consts.KonnectorType)) router.POST("/:slug", installHandler(consts.KonnectorType)) router.PUT("/:slug", updateHandler(consts.KonnectorType)) diff --git a/web/auth/auth_test.go b/web/auth/auth_test.go index 891af17b960..71a2df63b93 100644 --- a/web/auth/auth_test.go +++ b/web/auth/auth_test.go @@ -125,7 +125,7 @@ func TestAuth(t *testing.T) { t.Run("HomeWhenNotLoggedIn", func(t *testing.T) { e := testutils.CreateTestClient(t, ts.URL) - e.GET("/"). + e.GET(""). WithHost(domain). WithRedirectPolicy(httpexpect.DontFollowRedirects). Expect().Status(303). @@ -135,7 +135,7 @@ func TestAuth(t *testing.T) { t.Run("HomeWhenNotLoggedInWithJWT", func(t *testing.T) { e := testutils.CreateTestClient(t, ts.URL) - e.GET("/").WithQuery("jwt", "foobar"). + e.GET("").WithQuery("jwt", "foobar"). WithHost(domain). WithRedirectPolicy(httpexpect.DontFollowRedirects). Expect().Status(303). @@ -320,7 +320,7 @@ func TestAuth(t *testing.T) { t.Run("HomeWhenLoggedIn", func(t *testing.T) { e := testutils.CreateTestClient(t, ts.URL) - e.GET("/"). + e.GET(""). WithHost(domain). WithRedirectPolicy(httpexpect.DontFollowRedirects). WithCookie(session.CookieName(testInstance), sessionID). @@ -1896,7 +1896,7 @@ func TestAuth(t *testing.T) { require.False(t, inst.OnboardingFinished) // Should redirect to /auth/passphrase - e.GET("/"). + e.GET(""). WithQuery("registerToken", hex.EncodeToString(inst.RegisterToken)). WithHost(inst.Domain). WithRedirectPolicy(httpexpect.DontFollowRedirects). @@ -1914,7 +1914,7 @@ func TestAuth(t *testing.T) { inst.OnboardingFinished = true - e.GET("/"). + e.GET(""). WithQuery("registerToken", hex.EncodeToString(inst.RegisterToken)). WithHost(domain). WithRedirectPolicy(httpexpect.DontFollowRedirects). diff --git a/web/compat/compat.go b/web/compat/compat.go index cd20a2c5cd9..e210a7ba407 100644 --- a/web/compat/compat.go +++ b/web/compat/compat.go @@ -22,6 +22,4 @@ func Compat(c echo.Context) error { func Routes(router *echo.Group) { router.GET("", Compat) router.HEAD("", Compat) - router.GET("/", Compat) - router.HEAD("/", Compat) } diff --git a/web/data/data.go b/web/data/data.go index 66ef71c7f17..bba0b345d2c 100644 --- a/web/data/data.go +++ b/web/data/data.go @@ -563,7 +563,7 @@ func Routes(router *echo.Group) { router.Use(couchdbStyleErrorHandler) // API Routes that don't depend on a doctype - router.GET("/", dataAPIWelcome) + router.GET("", dataAPIWelcome) router.GET("/_all_doctypes", allDoctypes) // API Routes under /:doctype @@ -576,7 +576,7 @@ func Routes(router *echo.Group) { group.GET("/:docid", getDoc) group.PUT("/:docid", UpdateDoc) group.DELETE("/:docid", DeleteDoc) - group.POST("/", createDoc) + group.POST("", createDoc) group.GET("/_all_docs", allDocs) group.POST("/_all_docs", allDocs) group.GET("/_normal_docs", normalDocs) @@ -588,5 +588,5 @@ func Routes(router *echo.Group) { group.POST("/_design/:designdocid/copy", copyDesignDoc) group.DELETE("/_design/:designdocid", deleteDesignDoc) - group.DELETE("/", DeleteDatabase) + group.DELETE("", DeleteDatabase) } diff --git a/web/data/replication.go b/web/data/replication.go index eb6b58dccc3..8d2340f9cda 100644 --- a/web/data/replication.go +++ b/web/data/replication.go @@ -278,10 +278,10 @@ func dbStatus(c echo.Context) error { } func replicationRoutes(group *echo.Group) { - group.PUT("/", createDB) + group.PUT("", createDB) // Routes used only for replication - group.GET("/", dbStatus) + group.GET("", dbStatus) group.GET("/_changes", changesFeed) // POST=GET+filter see http://docs.couchdb.org/en/stable/api/database/changes.html#post--db-_changes) group.POST("/_changes", changesFeed) diff --git a/web/files/files.go b/web/files/files.go index ffd86a808c0..51661475350 100644 --- a/web/files/files.go +++ b/web/files/files.go @@ -1839,9 +1839,9 @@ func Routes(router *echo.Group) { router.PATCH("/metadata", ModifyMetadataByPathHandler) router.PATCH("/:file-id", ModifyMetadataByIDHandler) - router.PATCH("/", ModifyMetadataByIDInBatchHandler) + router.PATCH("", ModifyMetadataByIDInBatchHandler) - router.POST("/", CreationHandler) + router.POST("", CreationHandler) router.POST("/:file-id", CreationHandler) router.PUT("/:file-id", OverwriteFileContentHandler) router.POST("/upload/metadata", UploadMetadataHandler) diff --git a/web/realtime/realtime.go b/web/realtime/realtime.go index d4941820871..b75cbd65194 100644 --- a/web/realtime/realtime.go +++ b/web/realtime/realtime.go @@ -334,6 +334,6 @@ func Notify(c echo.Context) error { // Routes set the routing for the realtime service func Routes(router *echo.Group) { - router.GET("/", Ws) + router.GET("", Ws) router.POST("/:doctype/:id", Notify) } diff --git a/web/registry/registry.go b/web/registry/registry.go index 036ac9b3bf5..2fa050bc977 100644 --- a/web/registry/registry.go +++ b/web/registry/registry.go @@ -159,7 +159,6 @@ func proxyMaintenanceReq(c echo.Context) error { func Routes(router *echo.Group) { gzip := middleware.Gzip() router.GET("", proxyListReq, gzip) - router.GET("/", proxyListReq, gzip) router.GET("/maintenance", proxyMaintenanceReq, gzip) router.GET("/:app", proxyAppReq, gzip) router.GET("/:app/icon", proxyReq(authed, shortClientCache, registry.NoCache)) diff --git a/web/routing.go b/web/routing.go index dd99c1bcd49..f36bb50ec1e 100644 --- a/web/routing.go +++ b/web/routing.go @@ -199,7 +199,7 @@ func SetupRoutes(router *echo.Echo) error { middlewares.CheckInstanceDeleting, } - router.GET("/", auth.Home, mws...) + router.GET("", auth.Home, mws...) auth.Routes(router.Group("/auth", mws...)) public.Routes(router.Group("/public", mws...)) wellknown.Routes(router.Group("/.well-known", mws...)) diff --git a/web/server.go b/web/server.go index 4356ae3e5ae..4c5420054e1 100644 --- a/web/server.go +++ b/web/server.go @@ -110,6 +110,7 @@ func checkExists(filepath string) error { // them. func ListenAndServe() (*Servers, error) { e := echo.New() + e.Pre(middleware.RemoveTrailingSlash()) e.HideBanner = true e.HidePort = true @@ -132,6 +133,7 @@ func ListenAndServe() (*Servers, error) { } admin := echo.New() + e.Pre(middleware.RemoveTrailingSlash()) admin.HideBanner = true admin.HidePort = true diff --git a/web/sharings/replicator.go b/web/sharings/replicator.go index c379b43226c..3c48da22ad5 100644 --- a/web/sharings/replicator.go +++ b/web/sharings/replicator.go @@ -162,14 +162,13 @@ func EndInitial(c echo.Context) error { // replicatorRoutes sets the routing for the replicator func replicatorRoutes(router *echo.Group) { - group := router.Group("", checkSharingPermissions) - group.POST("/:sharing-id/_revs_diff", RevsDiff, checkSharingWritePermissions) - group.POST("/:sharing-id/_bulk_docs", BulkDocs, checkSharingWritePermissions) - group.GET("/:sharing-id/io.cozy.files/:id", GetFolder, checkSharingReadPermissions) - group.PUT("/:sharing-id/io.cozy.files/:id/metadata", SyncFile, checkSharingWritePermissions) - group.PUT("/:sharing-id/io.cozy.files/:id", FileHandler, checkSharingWritePermissions) - group.POST("/:sharing-id/reupload", ReuploadHandler, checkSharingReadPermissions) - group.DELETE("/:sharing-id/initial", EndInitial, checkSharingWritePermissions) + router.POST("/:sharing-id/_revs_diff", RevsDiff, checkSharingPermissions, checkSharingWritePermissions) + router.POST("/:sharing-id/_bulk_docs", BulkDocs, checkSharingPermissions, checkSharingWritePermissions) + router.GET("/:sharing-id/io.cozy.files/:id", GetFolder, checkSharingPermissions, checkSharingReadPermissions) + router.PUT("/:sharing-id/io.cozy.files/:id/metadata", SyncFile, checkSharingPermissions, checkSharingWritePermissions) + router.PUT("/:sharing-id/io.cozy.files/:id", FileHandler, checkSharingPermissions, checkSharingWritePermissions) + router.POST("/:sharing-id/reupload", ReuploadHandler, checkSharingPermissions, checkSharingReadPermissions) + router.DELETE("/:sharing-id/initial", EndInitial, checkSharingPermissions, checkSharingWritePermissions) } func checkSharingReadPermissions(next echo.HandlerFunc) echo.HandlerFunc { diff --git a/web/sharings/sharings.go b/web/sharings/sharings.go index 107331d5b9b..b791f5622e7 100644 --- a/web/sharings/sharings.go +++ b/web/sharings/sharings.go @@ -701,7 +701,7 @@ func localAvatar(c echo.Context, m sharing.Member) error { // Routes sets the routing for the sharing service func Routes(router *echo.Group) { // Create a sharing - router.POST("/", CreateSharing) // On the sharer + router.POST("", CreateSharing) // On the sharer router.PUT("/:sharing-id", PutSharing) // On a recipient router.GET("/:sharing-id", GetSharing) router.POST("/:sharing-id/answer", AnswerSharing) diff --git a/web/status/status.go b/web/status/status.go index e553be69223..ffa1eaae6ce 100644 --- a/web/status/status.go +++ b/web/status/status.go @@ -81,6 +81,4 @@ func Status(c echo.Context) error { func Routes(router *echo.Group) { router.GET("", Status) router.HEAD("", Status) - router.GET("/", Status) - router.HEAD("/", Status) } diff --git a/web/version/version.go b/web/version/version.go index 38208c0592a..8d14cae9331 100644 --- a/web/version/version.go +++ b/web/version/version.go @@ -23,6 +23,4 @@ func Version(c echo.Context) error { func Routes(router *echo.Group) { router.GET("", Version) router.HEAD("", Version) - router.GET("/", Version) - router.HEAD("/", Version) }