]> gitweb @ CieloNegro.org - Lucu.git/blob - examples/HelloWorld.hs
Use base64-bytestring instead of dataenc
[Lucu.git] / examples / HelloWorld.hs
1 import Network.HTTP.Lucu
2
3 main :: IO ()
4 main = let config    = defaultConfig { cnfServerPort = "9999" }
5            resources = mkResTree [ ( []
6                                    , helloWorld )
7
8                                  , ( ["urandom"]
9                                    , staticFile "/dev/urandom" )
10
11                                  , ( ["inc"]
12                                    , staticDir "/usr/include" )
13                                  ]
14            fallbacks = [ \ path -> case path of
15                                      ["hello"] -> return $ Just helloWorld
16                                      _         -> return Nothing
17                        ]
18        in
19          do putStrLn "Access http://localhost:9999/ with your browser."
20             runHttpd config resources fallbacks
21
22
23 helloWorld :: ResourceDef
24 helloWorld
25     = emptyResource {
26         resGet
27           = Just $ do --time <- liftIO $ getClockTime
28                       --foundEntity (strongETag "abcde") time
29                       setContentType $ read "text/hello"
30                       outputChunk "Hello, "
31                       outputChunk "World!\n"
32                       outputChunk =<< getRemoteAddr'
33                       
34       , resPost
35           = Just $ do str1 <- inputChunk 3
36                       str2 <- inputChunk 3
37                       str3 <- inputChunk 3
38                       setContentType $ read "text/hello"
39                       output ("[" ++ str1 ++ " - " ++ str2 ++ "#" ++ str3 ++ "]")
40       }