    --------------------------------------------------------------------------------
    -- | 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
                 -> Static.StaticSettings -- ^ Static file server settings
                 -> String               -- ^ Host to bind on
                 -> Int                  -- ^ Port to listen on
                 -> IO ()                -- ^ Blocks forever
    staticServer :: Logger -> StaticSettings -> [Char] -> Int -> IO ()
    staticServer Logger
    logger StaticSettings
    settings [Char]
    host Int
    port = do
        Logger -> [Char] -> IO ()
    forall (m :: * -> *). MonadIO m => Logger -> [Char] -> m ()
    Logger.header Logger
    logger ([Char] -> IO ()) -> [Char] -> IO ()
    forall a b. (a -> b) -> a -> b
    $ [Char]
    "Listening on http://" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    host [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ [Char]
    ":" [Char] -> [Char] -> [Char]
    forall a. [a] -> [a] -> [a]
    ++ Int -> [Char]
    forall a. Show a => a -> [Char]
    show Int
    port
        Logger -> forall (m :: * -> *). MonadIO m => m ()
    Logger.flush Logger
    logger -- ensure this line is logged before Warp errors
        Settings -> Application -> IO ()
    Warp.runSettings Settings
    warpSettings (Application -> IO ()) -> Application -> IO ()
    forall a b. (a -> b) -> a -> b
    $ StaticSettings -> Application
    Static.staticApp StaticSettings
    settings
      where
        warpSettings :: Settings
    warpSettings = (Request -> Status -> Maybe Integer -> IO ())
    -> Settings -> Settings
    Warp.setLogger Request -> Status -> Maybe Integer -> IO ()
    noLog
            (Settings -> Settings) -> Settings -> Settings
    forall a b. (a -> b) -> a -> b
    $ HostPreference -> Settings -> Settings
    Warp.setHost ([Char] -> HostPreference
    forall a. IsString a => [Char] -> a
    fromString [Char]
    host)
            (Settings -> Settings) -> Settings -> Settings
    forall a b. (a -> b) -> a -> b
    $ Int -> Settings -> Settings
    Warp.setPort Int
    port Settings
    Warp.defaultSettings

    noLog :: Wai.Request -> Status -> Maybe Integer -> IO ()
    noLog :: Request -> Status -> Maybe Integer -> IO ()
    noLog Request
    _ Status
    _ Maybe Integer
    _ = () -> IO ()
    forall a. a -> IO a
    forall (m :: * -> *) a. Monad m => a -> m a
    return ()