refactor(tazblog): Move blog configuration to envvars

The port and resource directory are now specified via environment
variables and a wrapper script is created by Nix that sets the
resource path and so on correctly.
This commit is contained in:
Vincent Ambo 2019-08-23 12:03:17 +01:00
parent fb930e4db7
commit be074c6085
2 changed files with 24 additions and 22 deletions

View file

@ -1,28 +1,25 @@
-- | Main module for the blog's web server
module Main where
import Control.Applicative (pure, (<*>))
import Control.Exception (bracket)
import Data.Word (Word16)
import Locales (version)
import Network (HostName, PortID (..))
import Options
import Server
import Control.Applicative ((<$>), (<*>))
import Locales (version)
import Server (runBlog)
import System.Environment (getEnv)
data MainOptions = MainOptions {
blogPort :: Int,
resourceDir :: String
}
data MainOptions
= MainOptions
{ blogPort :: Int,
resourceDir :: String
}
instance Options MainOptions where
defineOptions = pure MainOptions
<*> simpleOption "blogPort" 8000
"Port to serve the blog on. Default is 8000."
<*> simpleOption "resourceDir" "/opt/tazblog/static"
"Resources folder location."
readOpts :: IO MainOptions
readOpts =
MainOptions
<$> (fmap read $ getEnv "PORT")
<*> getEnv "RESOURCE_DIR"
main :: IO()
main :: IO ()
main = do
putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
runCommand $ \opts _ ->
runBlog (blogPort opts) (resourceDir opts)
putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
opts <- readOpts
runBlog (blogPort opts) (resourceDir opts)