~alcinnz/bureaucromancy

ref: fa8b4face21b0a32e01a2b4e2669f7dce1a43626 bureaucromancy/app/Main.hs -rw-r--r-- 562 bytes
fa8b4fac — Adrian Cochrane Assemble testscript as locally-run webserver, adjust namespace. 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!"