32 lines
871 B
Haskell
32 lines
871 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
{-# LANGUAGE RecordWildCards #-}
|
|
|
|
module Main where
|
|
|
|
import Data.Semigroup ((<>))
|
|
import Network.Wai.Application.Static
|
|
import Network.Wai.Handler.Warp
|
|
import Network.Wai.Middleware.RequestLogger
|
|
import Options.Applicative
|
|
import System.FilePath
|
|
import WaiAppStatic.Types
|
|
import Data.Maybe
|
|
|
|
data Config = Config
|
|
{ location :: FilePath,
|
|
port :: Int
|
|
}
|
|
|
|
configP :: Parser Config
|
|
configP =
|
|
let location = strArgument (metavar "PATH" <> help "Directory to serve")
|
|
port = argument auto (metavar "PORT" <> value 12345)
|
|
in Config <$> location <*> port
|
|
|
|
main :: IO ()
|
|
main = do
|
|
Config {..} <- execParser $ info configP fullDesc
|
|
putStrLn $ "Location: " ++ location
|
|
putStrLn $ "Port: " ++ show port
|
|
run port . logStdout . staticApp $ (defaultWebAppSettings location) {ssIndices = fromMaybe [] $ toPieces ["index.html"]}
|