diff options
author | Lorenzo <lortabac@gmx.com> | 2016-07-22 17:02:04 +0200 |
---|---|---|
committer | Lorenzo <lortabac@gmx.com> | 2016-07-22 17:02:04 +0200 |
commit | 7a1989d288ac9f2e0d38e8f84509895c33780046 (patch) | |
tree | 4d397eb270aaeef5b42707c21f3ec37cead1f50e /src/Hakyll/Preview/Server.hs | |
parent | 3d713e9f2c08dc40e67340b9e6717bb6f6adb20c (diff) | |
parent | cb07202f5af0ac64f9aa4ccde9e9917f3ed01ed3 (diff) | |
download | hakyll-7a1989d288ac9f2e0d38e8f84509895c33780046.tar.gz |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/Hakyll/Preview/Server.hs')
-rw-r--r-- | src/Hakyll/Preview/Server.hs | 48 |
1 files changed, 14 insertions, 34 deletions
diff --git a/src/Hakyll/Preview/Server.hs b/src/Hakyll/Preview/Server.hs index 5de3d0c..ca02e2b 100644 --- a/src/Hakyll/Preview/Server.hs +++ b/src/Hakyll/Preview/Server.hs @@ -7,48 +7,28 @@ module Hakyll.Preview.Server -------------------------------------------------------------------------------- -import Control.Monad.Trans (liftIO) -import qualified Data.ByteString.Char8 as B -import qualified Snap.Core as Snap -import qualified Snap.Http.Server as Snap -import qualified Snap.Util.FileServe as Snap - +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 - --------------------------------------------------------------------------------- --- | Serve a given directory -static :: FilePath -- ^ Directory to serve - -> (FilePath -> IO ()) -- ^ Pre-serve hook - -> Snap.Snap () -static directory preServe = - Snap.serveDirectoryWith directoryConfig directory - where - directoryConfig :: Snap.DirectoryConfig Snap.Snap - directoryConfig = Snap.fancyDirectoryConfig - { Snap.preServeHook = liftIO . preServe - } - - --------------------------------------------------------------------------------- --- | Main method, runs a static server in the given directory staticServer :: Logger -- ^ Logger -> FilePath -- ^ Directory to serve - -> (FilePath -> IO ()) -- ^ Pre-serve hook -> String -- ^ Host to bind on -> Int -- ^ Port to listen on -> IO () -- ^ Blocks forever -staticServer logger directory preServe host port = do +staticServer logger directory host port = do Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port - Snap.httpServe config $ static directory preServe - where - -- Snap server config - config = Snap.setBind (B.pack host) - $ Snap.setPort port - $ Snap.setAccessLog Snap.ConfigNoLog - $ Snap.setErrorLog Snap.ConfigNoLog - $ Snap.setVerbose False - $ Snap.emptyConfig + let settings = Warp.setLogger noLog + $ Warp.setHost (fromString host) + $ Warp.setPort port Warp.defaultSettings + waiApp = Static.staticApp (Static.defaultWebAppSettings directory) + Warp.runSettings settings waiApp + +noLog :: Wai.Request -> Status -> Maybe Integer -> IO () +noLog _ _ _ = return () |