Fix redirecting / to /app

Before all paths not otherwise handled were redirected, but it should
only be the root path.
This commit is contained in:
Eike Kettner 2020-05-23 09:56:44 +02:00
parent 89fd91894d
commit 229baa0719
2 changed files with 12 additions and 7 deletions

View File

@ -17,6 +17,7 @@
from an item detail to the front-page, the search menu remembers the from an item detail to the front-page, the search menu remembers the
last state, but dates were cleared. last state, but dates were cleared.
- More fixes regarding character encodings when reading e-mails. - More fixes regarding character encodings when reading e-mails.
- Fix redirecting `/` to `/app`.
### Configuration Changes ### Configuration Changes

View File

@ -1,7 +1,7 @@
package docspell.restserver package docspell.restserver
import cats.effect._ import cats.effect._
import cats.data.{Kleisli, OptionT} import cats.implicits._
import docspell.common.Pools import docspell.common.Pools
import docspell.backend.auth.AuthToken import docspell.backend.auth.AuthToken
import docspell.restserver.routes._ import docspell.restserver.routes._
@ -13,6 +13,7 @@ import org.http4s.implicits._
import org.http4s.server.Router import org.http4s.server.Router
import org.http4s.server.blaze.BlazeServerBuilder import org.http4s.server.blaze.BlazeServerBuilder
import org.http4s.server.middleware.Logger import org.http4s.server.middleware.Logger
import org.http4s.dsl.Http4sDsl
object RestServer { object RestServer {
@ -88,14 +89,17 @@ object RestServer {
"checkfile" -> CheckFileRoutes.open(restApp.backend) "checkfile" -> CheckFileRoutes.open(restApp.backend)
) )
def redirectTo[F[_]: Effect](path: String): HttpRoutes[F] = def redirectTo[F[_]: Effect](path: String): HttpRoutes[F] = {
Kleisli(_ => val dsl = new Http4sDsl[F] {}
OptionT.pure( import dsl._
HttpRoutes.of {
case GET -> Root =>
Response[F]( Response[F](
Status.SeeOther, Status.SeeOther,
body = Stream.empty, body = Stream.empty,
headers = Headers.of(Location(Uri(path = path))) headers = Headers.of(Location(Uri(path = path)))
) ).pure[F]
) }
) }
} }