blob: 9f58327109cf7840051fad066377fe87d272a21d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE LambdaCase #-}
import Network.CGI (runCGI, handleErrors, outputFPS, setHeader)
import Text.Blaze.Html.Renderer.Utf8 (renderHtml)
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)
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 $ (loadConfig >>= runScript script)
|