From 8f7e8c7800562dff6b41913a5fff41b11f624801 Mon Sep 17 00:00:00 2001
From: Eike Kettner <eike.kettner@posteo.de>
Date: Sat, 18 Jan 2020 17:48:45 +0100
Subject: [PATCH] Add redirect for root (`/`) to gui (`/app`)

---
 .../scala/docspell/restserver/RestServer.scala | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala
index 160a92a7..7cf682c8 100644
--- a/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala
+++ b/modules/restserver/src/main/scala/docspell/restserver/RestServer.scala
@@ -1,11 +1,13 @@
 package docspell.restserver
 
 import cats.effect._
+import cats.data.{Kleisli, OptionT}
 import docspell.backend.auth.AuthToken
 import docspell.restserver.routes._
 import docspell.restserver.webapp._
 import fs2.Stream
-import org.http4s.HttpRoutes
+import org.http4s._
+import org.http4s.headers.Location
 import org.http4s.implicits._
 import org.http4s.server.Router
 import org.http4s.server.blaze.BlazeServerBuilder
@@ -33,7 +35,8 @@ object RestServer {
         },
         "/api/doc"    -> templates.doc,
         "/app/assets" -> WebjarRoutes.appRoutes[F](blocker),
-        "/app"        -> templates.app
+        "/app"        -> templates.app,
+        "/"           -> redirectTo("/app")
       ).orNotFound
 
       finalHttpApp = Logger.httpApp(logHeaders = false, logBody = false)(httpApp)
@@ -82,4 +85,15 @@ object RestServer {
       "upload"    -> UploadRoutes.open(restApp.backend, cfg),
       "checkfile" -> CheckFileRoutes.open(restApp.backend)
     )
+
+  def redirectTo[F[_]: Effect](path: String): HttpRoutes[F] =
+    Kleisli(_ =>
+      OptionT.pure(
+        Response[F](
+          Status.SeeOther,
+          body = Stream.empty,
+          headers = Headers.of(Location(Uri(path = path)))
+        )
+      )
+    )
 }