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
10 import Data.Monoid.Unicode
12 import Network.HTTP.Lucu
13 import Prelude.Unicode
16 main = let config = defaultConfig { cnfServerPort = "9999" }
17 mapper = resourceMap resources ⊕ resourceMap fallbacks
18 resources ∷ ResourceTree
19 resources = C.fromList
20 [ ([] , nonGreedy helloWorld)
21 , (["urandom" ], nonGreedy $ staticFile "/dev/urandom")
22 , (["inc" ], greedy $ staticDir "/usr/include")
23 , (["inc", "t"], nonGreedy $ staticFile "/usr/include/time.h")
25 fallbacks ∷ Path → Maybe (Path, Resource)
27 | path ≡ ["hello"] = Just (path, helloWorld)
30 do putStrLn "Access http://localhost:9999/ with your browser."
31 withSocketsDo $ runHttpd config mapper
34 helloWorld = C.fromList
36 , do setContentType [mimeType| text/hello |]
39 putChunks =≪ Lazy.pack <$> getRemoteAddr'
42 , do str1 ← getChunk 3
45 setContentType [mimeType| text/hello |]
46 putChunks $ Lazy.fromChunks ["[", str1, " - ", str2, "#", str3, "]"]