summaryrefslogtreecommitdiff
path: root/src/Main.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Main.hs')
-rw-r--r--src/Main.hs20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 9fda84b..9f58327 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -3,18 +3,22 @@
import Network.CGI (runCGI, handleErrors, outputFPS, setHeader)
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
-import Settlr.Config (withConfig, ScriptM)
+import Settlr.Config (loadConfig)
+import Settlr.Scripts (ScriptM, runScript)
import Settlr.Routes (loadRoute, Route(..))
import Settlr.Views.ErrorNotFound (viewErrorNotFound)
import Settlr.Views.Home (viewHome)
import Text.Blaze.Html5 (Html)
+import Network.CGI.Protocol (CGIResult)
-view :: Maybe Route -> ScriptM Html
-view (Just RouteHome) = viewHome
-view (Just RouteNew) = viewErrorNotFound
-view Nothing = viewErrorNotFound
+run :: Maybe Route -> ScriptM Html
+run (Just RouteHome) = viewHome
+run (Just RouteNew) = viewErrorNotFound
+run Nothing = viewErrorNotFound
+
+script :: ScriptM CGIResult
+script = do setHeader "Content-type" "text/html; charset=\"utf-8\""
+ loadRoute >>= run >>= outputFPS . renderHtml
main :: IO ()
-main = runCGI $ handleErrors $ withConfig $ do
- setHeader "Content-type" "text/html; charset=\"utf-8\""
- loadRoute >>= view >>= outputFPS . renderHtml
+main = runCGI $ handleErrors $ (loadConfig >>= runScript script)