Lucu-1.0: Embedded HTTP Server



The entry point of Lucu httpd.



runHttpd :: HostMapper α => Config -> α -> IO ()Source

This is the entry point of Lucu httpd. It listens to a socket and waits for clients. runHttpd never stops by itself so the only way to stop it is to raise an exception in the thread running it.


{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE QuasiQuotes #-} module Main where import qualified Data.Collections as C import Network import Network.HTTP.Lucu main :: IO () main = let config = defaultConfig tree :: ResourceTree tree = C.fromList [ ([], nonGreedy helloWorld) ] in Network.withSocketsDo . runHttpd config $ resourceMap tree helloWorld :: Network.HTTP.Lucu.Resource helloWorld = C.fromList [ ( Network.HTTP.Lucu.GET , do Network.HTTP.Lucu.setContentType [Network.HTTP.Lucu.mimeType| text/plain |] Network.HTTP.Lucu.putChunk "Hello, world!" } FIXME: use monad-parallel's MonadFork instead of IO.