-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.hs
More file actions
29 lines (24 loc) · 905 Bytes
/
Main.hs
File metadata and controls
29 lines (24 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{-# LANGUAGE OverloadedStrings #-}
import Blaze.ByteString.Builder (copyByteString)
import qualified Data.ByteString.UTF8 as BU
import Data.Monoid
import Network.HTTP.Types (status200)
import Network.Wai
import Network.Wai.Handler.Warp
main :: IO ()
main = do
let port = 3000
putStrLn $ "Listening on port " ++ show port
run port app
app :: Request -> (Response -> t) -> t
app req respond = respond $
case pathInfo req of
["yay"] -> yay
x -> index x
yay :: Response
yay = responseBuilder status200 [ ("Content-Type", "text/plain") ] $ mconcat $ map copyByteString
[ "yay" ]
index :: Show a => a -> Response
index x = responseBuilder status200 [("Content-Type", "text/html")] $ mconcat $ map copyByteString
[ "<p>Hello from ", BU.fromString $ show x, "!</p>"
, "<p><a href='/yay'>yay</a></p>\n" ]