~alcinnz/Hearth

ref: a5f3016db36f3af4201a8b26ef9c32751ca95277 Hearth/app/Main.hs -rw-r--r-- 566 bytes
a5f3016d — Adrian Cochrane Implement basic infrastructure for Hearth! 11 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.Wai.Handler.Warp
import Network.Wai
import Network.HTTP.Types
import Data.Text.Lazy (fromStrict)
import Data.Text.Lazy.Encoding (encodeUtf8)

import Hearth (renderPage)

main :: IO ()
main = do
  runEnv 2019 servePage

servePage :: Application
servePage req respond = case requestMethod req of
  "GET" | Just resp <- renderPage (rawPathInfo req) (queryString req) ->
    respond $ responseLBS status200 [] $ encodeUtf8 $ fromStrict resp
  _ -> respond $ responseLBS status404 [] "Page not found!"