about summary refs log tree commit diff
path: root/website/sandbox/learnpianochords/src/server/Main.hs
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-08-10T14·02+0100
committerWilliam Carroll <wpcarro@gmail.com>2020-08-10T14·02+0100
commit4ff1ea291c266c68acfd662b7439d5c2061907ea (patch)
treeb019dcc69bbf4964b1964650f1f4e66bbed49cac /website/sandbox/learnpianochords/src/server/Main.hs
parentf61ed25755da89f6068efb75642e2ac22d268278 (diff)
Drop support for ServantT transformer type for server
After burning a few hours wrestling with the type system, I decided to revert to
the simpler `Server API` type instead of the `ServantT` transformer type.

The problem is that I couldn't write a MonadError instance for `RIO Context`,
which is my `AppM` (i.e. application monad). Using `throwIO` in the server
handlers results in 500 errors, which is not what I wanted. I'm still pretty
fuzzy about what's happening; I now know that exception handling in Haskell is
pretty gnaryly. I may revisit this at a later time when my knowledge is more
extensive. For now: time to fry bigger fish.

An easier abstract is for me to pass `T.Context` into `server` as an argument,
which after all is what a Reader does.

TL;DR:
- Read server, client ports from .envrc
- Define a top-level Failure type (empty for now)
- Define a top-level Success type
- Define App as RIO Context (Either Failure Success)
Diffstat (limited to 'website/sandbox/learnpianochords/src/server/Main.hs')
-rw-r--r--website/sandbox/learnpianochords/src/server/Main.hs14
1 files changed, 10 insertions, 4 deletions
diff --git a/website/sandbox/learnpianochords/src/server/Main.hs b/website/sandbox/learnpianochords/src/server/Main.hs
index 36044d2585eb..a163c66cda07 100644
--- a/website/sandbox/learnpianochords/src/server/Main.hs
+++ b/website/sandbox/learnpianochords/src/server/Main.hs
@@ -2,7 +2,7 @@
 module Main where
 --------------------------------------------------------------------------------
 import RIO
-import Prelude (putStrLn)
+import Prelude (putStr, putStrLn)
 
 import qualified Types as T
 import qualified System.Envy as Envy
@@ -18,8 +18,8 @@ getAppContext = do
     Left err -> pure $ Left err
     Right T.Env{..} -> pure $ Right T.Context
       { contextGoogleClientID = envGoogleClientID
-      , contextClientPort = 8000
-      , contextServerPort = 3000
+      , contextServerPort = envServerPort
+      , contextClientPort = envClientPort
       }
 
 main :: IO ()
@@ -27,4 +27,10 @@ main = do
   mContext <- getAppContext
   case mContext of
     Left err -> putStrLn err
-    Right ctx -> runRIO ctx App.run
+    Right ctx -> do
+      result <- runRIO ctx App.run
+      case result of
+        Left err -> do
+          putStr "Something went wrong when executing the application: "
+          putStrLn $ show err
+        Right _ -> putStrLn "The application successfully executed."