aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-07-15 10:48:18 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-07-15 10:48:18 +0200
commit4ef5c4e29379c8eed49f6f24ab5f4a3d73cfe3a5 (patch)
tree9f487f97875dd383763d00c06a53fd01748cbf80 /app
parent8d72e6924cabe5131fd5a58bdea06a22ca0e271b (diff)
downloadCana-4ef5c4e29379c8eed49f6f24ab5f4a3d73cfe3a5.tar.gz
Cana-4ef5c4e29379c8eed49f6f24ab5f4a3d73cfe3a5.tar.bz2
Cana-4ef5c4e29379c8eed49f6f24ab5f4a3d73cfe3a5.zip
Implement XML configuration support
This alleviates the need to define the server in Haskell and re-compile the binary every time something in the configuration changes.
Diffstat (limited to 'app')
-rw-r--r--app/Main.hs38
1 files changed, 25 insertions, 13 deletions
diff --git a/app/Main.hs b/app/Main.hs
index 50ca151..29dfc95 100644
--- a/app/Main.hs
+++ b/app/Main.hs
@@ -1,19 +1,31 @@
-{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE LambdaCase #-}
module Main where
import Cana
-import Cana.Protocol
-import Cana.Router
-import Cana.Extra
+import Cana.Server
-defaultResponse :: GeminiResponse
-defaultResponse = GeminiResponse
- { responseStatus = codeSuccess
- , responseMeta = "text/gemini"
- , responseData = "# Hello World\nThis page was served by Cana."
- }
+import Data.Maybe
+import System.IO
+import System.Exit
+import System.Environment
main :: IO ()
-main = runGeminiServer Nothing defaultGeminiPort "certificate.crt" "private.key"
- [ (anyRoute, staticFiles "gmdocs")
- ]
+main = do
+ configPath <- configPath
+ config <- loadConfig configPath
+ case config of
+ Left err ->
+ printError "Error loading configuration:" err >> exitFailure
+
+ Right c -> runGeminiServer' c >>= \case
+ Left err -> printError "Server error:" err >> exitFailure
+ Right _ -> return ()
+
+ where
+ configPath = do
+ args <- getArgs
+ return . fromMaybe "cana.xml" $ listToMaybe args
+
+ printError title err = do
+ hPutStrLn stderr title
+ hPutStrLn stderr err