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