@@ -7,48 +7,28 @@ module Hakyll.Preview.Server
77
88
99--------------------------------------------------------------------------------
10−import Control.Monad.Trans (liftIO)
11−import qualified Data.ByteString.Char8 as B
12−import qualified Snap.Core as Snap
13−import qualified Snap.Http.Server as Snap
14−import qualified Snap.Util.FileServe as Snap
15−
10+import Data.String
11+import qualified Network.Wai.Handler.Warp as Warp
12+import qualified Network.Wai.Application.Static as Static
13+import qualified Network.Wai as Wai
14+import Network.HTTP.Types.Status (Status)
1615
1716--------------------------------------------------------------------------------
1817import Hakyll.Core.Logger (Logger)
1918import qualified Hakyll.Core.Logger as Logger
2019
21−
22−--------------------------------------------------------------------------------
23−-- | Serve a given directory
24−static :: FilePath -- ^ Directory to serve
25− -> (FilePath -> IO ()) -- ^ Pre-serve hook
26− -> Snap.Snap ()
27−static directory preServe =
28− Snap.serveDirectoryWith directoryConfig directory
29− where
30− directoryConfig :: Snap.DirectoryConfig Snap.Snap
31− directoryConfig = Snap.fancyDirectoryConfig
32− { Snap.preServeHook = liftIO . preServe
33− }
34−
35−
36−--------------------------------------------------------------------------------
37−-- | Main method, runs a static server in the given directory
3820staticServer :: Logger -- ^ Logger
3921 -> FilePath -- ^ Directory to serve
40− -> (FilePath -> IO ()) -- ^ Pre-serve hook
4122 -> String -- ^ Host to bind on
4223 -> Int -- ^ Port to listen on
4324 -> IO () -- ^ Blocks forever
44−staticServer logger directory preServe host port = do
25+staticServer logger directory host port = do
4526 Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port
46− Snap.httpServe config $ static directory preServe
47− where
48− -- Snap server config
49− config = Snap.setBind (B.pack host)
50− $ Snap.setPort port
51− $ Snap.setAccessLog Snap.ConfigNoLog
52− $ Snap.setErrorLog Snap.ConfigNoLog
53− $ Snap.setVerbose False
54− $ Snap.emptyConfig
27+ let settings = Warp.setLogger noLog
28+ $ Warp.setHost (fromString host)
29+ $ Warp.setPort port Warp.defaultSettings
30+ waiApp = Static.staticApp (Static.defaultWebAppSettings directory)
31+ Warp.runSettings settings waiApp
32+
33+noLog :: Wai.Request -> Status -> Maybe Integer -> IO ()
34+noLog _ _ _ = return ()