From 229baa07194e2e71474b37a213438f0e7f83f965 Mon Sep 17 00:00:00 2001 From: Eike Kettner Date: Sat, 23 May 2020 09:56:44 +0200 Subject: [PATCH] Fix redirecting `/` to `/app` Before all paths not otherwise handled were redirected, but it should only be the root path. --- Changelog.md | 1 + .../scala/docspell/restserver/RestServer.scala | 18 +++++++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7788e364..052e3846 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,7 @@ from an item detail to the front-page, the search menu remembers the last state, but dates were cleared. - More fixes regarding character encodings when reading e-mails. +- Fix redirecting `/` to `/app`. ### Configuration Changes diff --git a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala index 02008552..c53d5b63 100644 --- a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala +++ b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala @@ -1,7 +1,7 @@ package docspell.restserver import cats.effect._ -import cats.data.{Kleisli, OptionT} +import cats.implicits._ import docspell.common.Pools import docspell.backend.auth.AuthToken import docspell.restserver.routes._ @@ -13,6 +13,7 @@ import org.http4s.implicits._ import org.http4s.server.Router import org.http4s.server.blaze.BlazeServerBuilder import org.http4s.server.middleware.Logger +import org.http4s.dsl.Http4sDsl object RestServer { @@ -88,14 +89,17 @@ object RestServer { "checkfile" -> CheckFileRoutes.open(restApp.backend) ) - def redirectTo[F[_]: Effect](path: String): HttpRoutes[F] = - Kleisli(_ => - OptionT.pure( + def redirectTo[F[_]: Effect](path: String): HttpRoutes[F] = { + val dsl = new Http4sDsl[F] {} + import dsl._ + + HttpRoutes.of { + case GET -> Root => Response[F]( Status.SeeOther, body = Stream.empty, headers = Headers.of(Location(Uri(path = path))) - ) - ) - ) + ).pure[F] + } + } }