From 67ecff7ad383640bc73d64edc2506c7cc648a134 Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Mon, 19 Jun 2017 11:57:23 +0200 Subject: Move src/ to lib/, put Init.hs in src/ --- lib/Hakyll/Preview/Server.hs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/Hakyll/Preview/Server.hs (limited to 'lib/Hakyll/Preview/Server.hs') diff --git a/lib/Hakyll/Preview/Server.hs b/lib/Hakyll/Preview/Server.hs new file mode 100644 index 0000000..a84016a --- /dev/null +++ b/lib/Hakyll/Preview/Server.hs @@ -0,0 +1,35 @@ +-------------------------------------------------------------------------------- +-- | Implements a basic static file server for previewing options +{-# LANGUAGE OverloadedStrings #-} +module Hakyll.Preview.Server + ( staticServer + ) where + + +-------------------------------------------------------------------------------- +import Data.String +import qualified Network.Wai.Handler.Warp as Warp +import qualified Network.Wai.Application.Static as Static +import qualified Network.Wai as Wai +import Network.HTTP.Types.Status (Status) + +-------------------------------------------------------------------------------- +import Hakyll.Core.Logger (Logger) +import qualified Hakyll.Core.Logger as Logger + +staticServer :: Logger -- ^ Logger + -> FilePath -- ^ Directory to serve + -> String -- ^ Host to bind on + -> Int -- ^ Port to listen on + -> IO () -- ^ Blocks forever +staticServer logger directory host port = do + Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port + Warp.runSettings warpSettings $ + Static.staticApp (Static.defaultFileServerSettings directory) + where + warpSettings = Warp.setLogger noLog + $ Warp.setHost (fromString host) + $ Warp.setPort port Warp.defaultSettings + +noLog :: Wai.Request -> Status -> Maybe Integer -> IO () +noLog _ _ _ = return () -- cgit v1.2.3