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