on dc830bd help sign in
typeable/wai/test.hs
29 lines 754 B history raw
1{-# LANGUAGE Rank2Types #-}
2import Network.Wai
3import Network.Wai.Handler.SimpleServer
4import qualified Data.ByteString.Char8 as B8
6main :: IO ()
7main = putStrLn "http://localhost:3000/" >> run 3000 app
9app :: Application
10app req = case B8.unpack $ pathInfo req of
11 "/post/" -> postResponse $ requestBody req
12 _ -> indexResponse
14indexResponse :: IO Response
15indexResponse = return Response
16 { status = Status200
17 , headers = [(ContentType, B8.pack "text/html")]
18 , body = index
19 }
21postResponse :: (forall a. Enumerator a) -> IO Response
22postResponse rb = return Response
23 { status = Status200
24 , headers = [(ContentType, B8.pack "text/plain")]
25 , body = Right rb
26 }
28index :: Either FilePath a
29index = Left "index.html"