on 73e78f6 help sign in
typeable/wai/webkit-sample/webkit-sample.hs
30 lines 875 B history raw
1{-# LANGUAGE Rank2Types #-}
2{-# LANGUAGE OverloadedStrings #-}
3import Network.Wai
4import Network.Wai.Handler.Webkit
5import Data.ByteString (ByteString)
6import qualified Data.ByteString.Lazy as L
7import Data.Enumerator (consume, Iteratee)
8import Blaze.ByteString.Builder (fromLazyByteString)
10main :: IO ()
11main = putStrLn "http://localhost:3000/" >> run "Webkit Sample" app
13app :: Application
14app req = case pathInfo req of
15 "/post/" -> do
16 bss <- consume
17 postResponse $ L.fromChunks bss
18 _ -> indexResponse
20indexResponse :: Iteratee ByteString IO Response
21indexResponse = return $ ResponseFile
22 status200
23 [("Content-Type" , "text/html")]
24 "index.html"
26postResponse :: L.ByteString -> Iteratee ByteString IO Response
27postResponse lbs = return $ ResponseBuilder
28 status200
29 [("Content-Type", "text/plain")]
30 (fromLazyByteString lbs)