diff options
author | Vincent Ambo <tazjin@google.com> | 2019-08-23T11·03+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-08-23T11·03+0100 |
commit | be074c60850a8bd6197e627c131d73e34d8640be (patch) | |
tree | 9d79a8e7e86807144f598cc509cdcfbc70a117b3 /services/tazblog/blog | |
parent | fb930e4db76fa71349dfeea78bdf34fb45b574c1 (diff) |
refactor(tazblog): Move blog configuration to envvars r/55
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.
Diffstat (limited to 'services/tazblog/blog')
-rw-r--r-- | services/tazblog/blog/Main.hs | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/services/tazblog/blog/Main.hs b/services/tazblog/blog/Main.hs index 246f1325e7fc..2842d1ee1b72 100644 --- a/services/tazblog/blog/Main.hs +++ b/services/tazblog/blog/Main.hs @@ -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) |