2015-11-19 19:28:36 +01:00
|
|
|
-- | Main module for the blog's web server
|
2012-02-22 22:03:31 +01:00
|
|
|
module Main where
|
|
|
|
|
2015-11-19 19:28:36 +01:00
|
|
|
import BlogDB (initialBlogState)
|
|
|
|
import Control.Applicative (pure, (<$>), (<*>))
|
|
|
|
import Control.Exception (bracket)
|
2012-03-07 17:31:42 +01:00
|
|
|
import Data.Acid
|
2015-11-19 19:28:36 +01:00
|
|
|
import Data.Acid.Remote
|
|
|
|
import Data.Word (Word16)
|
|
|
|
import Locales (version)
|
|
|
|
import Network (HostName, PortID (..))
|
2012-03-25 19:29:38 +02:00
|
|
|
import Options
|
2014-05-18 22:39:38 +02:00
|
|
|
import Server
|
2012-02-22 22:03:31 +01:00
|
|
|
|
2014-03-11 18:12:51 +01:00
|
|
|
data MainOptions = MainOptions {
|
2015-11-19 19:28:36 +01:00
|
|
|
dbHost :: String,
|
|
|
|
dbPort :: Word16,
|
|
|
|
blogPort :: Int,
|
|
|
|
resourceDir :: String
|
2014-03-11 18:12:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
instance Options MainOptions where
|
|
|
|
defineOptions = pure MainOptions
|
2015-11-19 19:28:36 +01:00
|
|
|
<*> simpleOption "dbHost" "localhost"
|
|
|
|
"Remote acid-state database host. Default is localhost"
|
|
|
|
<*> simpleOption "dbPort" 8070
|
|
|
|
"Remote acid-state database port. Default is 8070"
|
|
|
|
<*> simpleOption "blogPort" 8000
|
|
|
|
"Port to serve the blog on. Default is 8000."
|
|
|
|
<*> simpleOption "resourceDir" "/opt/tazblog/res"
|
2014-03-11 18:22:59 +01:00
|
|
|
"Resources folder location."
|
2015-11-19 19:28:36 +01:00
|
|
|
|
2012-03-09 17:57:53 +01:00
|
|
|
main :: IO()
|
|
|
|
main = do
|
|
|
|
putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
|
2015-11-19 19:28:36 +01:00
|
|
|
runCommand $ \opts _ ->
|
|
|
|
let port = PortNumber $ fromIntegral $ dbPort opts
|
|
|
|
in openRemoteState skipAuthenticationPerform (dbHost opts) port >>=
|
|
|
|
(\acid -> runBlog acid (blogPort opts) (resourceDir opts))
|
2012-03-06 00:50:53 +01:00
|
|
|
|
2012-03-13 06:35:56 +01:00
|
|
|
|