blob: ca02e2b005fb7075af57749b8a1daa9f1b453adb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
--------------------------------------------------------------------------------
-- | 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
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 ()
|