6 import Control.Applicative
7 import Control.Monad.Unicode
8 import qualified Data.ByteString.Lazy.Char8 as Lazy
9 import qualified Data.Collections as C
11 import Data.Monoid.Unicode
13 import Network.HTTP.Lucu
14 import Prelude.Unicode
17 main = let config = def { cnfServerPort = "9999" }
18 mapper = resourceMap resources ⊕ resourceMap fallbacks
19 resources ∷ ResourceTree
20 resources = C.fromList
21 [ ([] , nonGreedy helloWorld)
22 , (["urandom" ], nonGreedy $ staticFile "/dev/urandom")
23 , (["inc" ], greedy $ staticDir "/usr/include")
24 , (["inc", "t"], nonGreedy $ staticFile "/usr/include/time.h")
26 fallbacks ∷ Path → Maybe (Path, Resource)
28 | path ≡ ["hello"] = Just (path, helloWorld)
31 do putStrLn "Access http://localhost:9999/ with your browser."
32 withSocketsDo $ runHttpd config mapper
35 helloWorld = C.fromList
37 , do setContentType [mimeType| text/hello |]
40 putChunks =≪ Lazy.pack <$> getRemoteAddr'
43 , do str1 ← getChunk 3
46 setContentType [mimeType| text/hello |]
47 putChunks $ Lazy.fromChunks ["[", str1, " - ", str2, "#", str3, "]"]