~alcinnz/bureaucromancy

ref: 74eb3d0a76804b282578ac1e364bfb6d855e9a02 bureaucromancy/app/Main.hs -rw-r--r-- 562 bytes
74eb3d0a — Adrian Cochrane Add project links to readme! 1 year, 4 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 Text.HTML.Form.WebApp
import Data.Text.Lazy.Encoding (encodeUtf8)
import Data.Text.Lazy (fromStrict)

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

servePage req respond = do
    ret <- renderPage Form (pathInfo req) (queryString req)
    case ret of
        Just txt -> respond $ responseLBS status200 [] $ encodeUtf8 $ fromStrict txt
        Nothing -> respond $ responseLBS status404 [] "Unknown input or operation!"