@@ -12,20 +12,22 @@ import schema._
12
12
import org .http4s ._
13
13
import org .http4s .circe ._
14
14
import org .http4s .dsl ._
15
+ import org .http4s .headers .Location
15
16
import org .http4s .implicits ._
16
17
import org .http4s .server .Server
17
18
import org .http4s .server .blaze ._
19
+
18
20
import scala .concurrent .ExecutionContext
19
21
20
22
object Main extends IOApp {
21
23
22
- // Construct a transctor for connecting to the database.
24
+ // Construct a transactor for connecting to the database.
23
25
def transactor [F [_]: Async : ContextShift ] =
24
26
Transactor .fromDriverManager[F ](
25
27
" org.postgresql.Driver" ,
26
28
" jdbc:postgresql:world" ,
27
- " postgres " ,
28
- " "
29
+ " user " ,
30
+ " password "
29
31
)
30
32
31
33
// Construct a GraphQL implementation based on our Sangria definitions.
@@ -44,20 +46,25 @@ object Main extends IOApp {
44
46
graphQL : GraphQL [F ],
45
47
blockingContext : ExecutionContext
46
48
): HttpRoutes [F ] = {
49
+
47
50
object dsl extends Http4sDsl [F ]; import dsl ._
51
+
48
52
HttpRoutes .of[F ] {
49
53
50
- case GET -> Root =>
54
+ case GET -> Root / " playground.html " =>
51
55
StaticFile
52
- .fromResource[F ](" /assets/graphiql .html" , blockingContext)
56
+ .fromResource[F ](" /assets/playground .html" , blockingContext)
53
57
.getOrElseF(NotFound ())
54
-
58
+
55
59
case req @ POST -> Root / " graphql" ⇒
56
60
req.as[Json ].flatMap(graphQL.query).flatMap {
57
61
case Right (json) => Ok (json)
58
62
case Left (json) => BadRequest (json)
59
63
}
60
64
65
+ case _ =>
66
+ PermanentRedirect (Location (Uri .uri(" /playground.html" )))
67
+
61
68
}
62
69
}
63
70
0 commit comments