aboutsummaryrefslogtreecommitdiffstats
path: root/app/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs28
1 files changed, 18 insertions, 10 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 945bfc9..3b7f59d 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,3 +1,5 @@
+{-# LANGUAGE LambdaCase #-}
+
module Main
( main,
)
@@ -9,6 +11,7 @@ import Data.Aeson qualified as J
import Data.ByteString.Lazy.Char8 qualified as LB
import Data.ByteString.Lazy.UTF8 qualified as LB
import Data.String (IsString (fromString))
+import Data.Vector qualified as V
import Network.HTTP.Types.Method qualified as W
import Network.HTTP.Types.Status qualified as W
import Network.Wai qualified as W
@@ -63,7 +66,12 @@ main = do
R.evalRepl
(const . pure $ ">>> ")
( liftIO
- . (mapM_ (LB.putStrLn . J.encode) =<<)
+ . ( ( \case
+ J.Array xs -> mapM_ (LB.putStrLn . J.encode) (V.toList xs)
+ x -> LB.putStrLn (J.encode x)
+ )
+ =<<
+ )
. Q.withStore root ref
. Q.query
. fromString
@@ -77,12 +85,12 @@ main = do
Args {cmd = Serve} -> do
W.runEnv 8080 $ \req respond -> do
if
- | W.requestMethod req == W.methodPost -> do
- q <-
- fromString @Q.Query . LB.toString
- <$> W.lazyRequestBody req
- r <- liftIO $ Q.withStore root ref (Q.query q)
- respond . W.responseLBS W.status200 [] $
- J.encode r
- | otherwise ->
- respond $ W.responseLBS W.status200 [] "OK"
+ | W.requestMethod req == W.methodPost -> do
+ q <-
+ fromString @Q.Query . LB.toString
+ <$> W.lazyRequestBody req
+ r <- liftIO $ Q.withStore root ref (Q.query q)
+ respond . W.responseLBS W.status200 [] $
+ J.encode r
+ | otherwise ->
+ respond $ W.responseLBS W.status200 [] "OK"