diff --git a/lib/Hakyll/Commands.hs b/lib/Hakyll/Commands.hs index 0da749a7..4fe879ef 100644 --- a/lib/Hakyll/Commands.hs +++ b/lib/Hakyll/Commands.hs @@ -124,8 +124,8 @@ rebuild conf logger rules = server :: Configuration -> Logger -> String -> Int -> IO () #ifdef PREVIEW_SERVER server conf logger host port = do - let destination = destinationDirectory conf - staticServer logger destination host port + let settings = previewSettings conf $ destinationDirectory conf + staticServer logger settings host port #else server _ _ _ _ = previewServerDisabled #endif diff --git a/lib/Hakyll/Core/Configuration.hs b/lib/Hakyll/Core/Configuration.hs index 45b626e9..9d711232 100644 --- a/lib/Hakyll/Core/Configuration.hs +++ b/lib/Hakyll/Core/Configuration.hs @@ -11,6 +11,7 @@ module Hakyll.Core.Configuration -------------------------------------------------------------------------------- import Data.Default (Default (..)) import Data.List (isPrefixOf, isSuffixOf) +import qualified Network.Wai.Application.Static as Static import System.Directory (canonicalizePath) import System.Exit (ExitCode) import System.FilePath (isAbsolute, normalise, takeFileName, makeRelative) @@ -87,6 +88,9 @@ data Configuration = Configuration -- One can also override the port as a command line argument: -- ./site preview -p 1234 previewPort :: Int + -- | Override other settings used by the preview server. Default is + -- 'Static.defaultFileServerSettings'. + , previewSettings :: FilePath -> Static.StaticSettings } -------------------------------------------------------------------------------- @@ -108,6 +112,7 @@ defaultConfiguration = Configuration , inMemoryCache = True , previewHost = "127.0.0.1" , previewPort = 8000 + , previewSettings = Static.defaultFileServerSettings } where ignoreFile' path diff --git a/lib/Hakyll/Preview/Server.hs b/lib/Hakyll/Preview/Server.hs index 828a1d25..dcd6f594 100644 --- a/lib/Hakyll/Preview/Server.hs +++ b/lib/Hakyll/Preview/Server.hs @@ -18,15 +18,14 @@ import Hakyll.Core.Logger (Logger) import qualified Hakyll.Core.Logger as Logger staticServer :: Logger -- ^ Logger - -> FilePath -- ^ Directory to serve + -> Static.StaticSettings -- ^ Static file server settings -> String -- ^ Host to bind on -> Int -- ^ Port to listen on -> IO () -- ^ Blocks forever -staticServer logger directory host port = do +staticServer logger settings host port = do Logger.header logger $ "Listening on http://" ++ host ++ ":" ++ show port Logger.flush logger -- ensure this line is logged before Warp errors - Warp.runSettings warpSettings $ - Static.staticApp (Static.defaultFileServerSettings directory) + Warp.runSettings warpSettings $ Static.staticApp settings where warpSettings = Warp.setLogger noLog $ Warp.setHost (fromString host)