{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Rib.Server
(
serve
, getHTMLFileUrl
)
where
import Prelude hiding (init, last)
import Data.Text (Text)
import qualified Data.Text as T
import Development.Shake.FilePath ((-<.>))
import Network.Wai.Application.Static (defaultFileServerSettings, ssListing, ssLookupFile, staticApp)
import qualified Network.Wai.Handler.Warp as Warp
import WaiAppStatic.Types (StaticSettings)
staticSiteServerSettings :: FilePath -> StaticSettings
staticSiteServerSettings root = settings
{ ssLookupFile = ssLookupFile settings
, ssListing = Nothing
}
where
settings = defaultFileServerSettings root
getHTMLFileUrl
:: FilePath
-> Text
getHTMLFileUrl path = T.pack $ "/" ++ (path -<.> ".html")
serve
:: Int
-> FilePath
-> IO ()
serve port path = do
putStrLn $ "[Rib] Serving at http://localhost:" <> show port
Warp.run port $ staticApp $ staticSiteServerSettings path