about summary refs log tree commit diff
path: root/services/tazblog/blog/Main.hs
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-06-29T13·02+0100
committerVincent Ambo <tazjin@google.com>2019-06-29T13·02+0100
commit207c6dac0c27c70429043b94b5ccd10979489230 (patch)
treef79bdce9a8683851e648576b47147463d04193c2 /services/tazblog/blog/Main.hs
parentb6813682176b8b4a944df94794982e81d2a9414f (diff)
parent47f2145b5b39b63500fe2d9d0a64edc44edaa793 (diff)
merge(tazblog): Integrate blog into monorepo r/2
Diffstat (limited to 'services/tazblog/blog/Main.hs')
-rw-r--r--services/tazblog/blog/Main.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/services/tazblog/blog/Main.hs b/services/tazblog/blog/Main.hs
new file mode 100644
index 000000000000..cfe068a8d988
--- /dev/null
+++ b/services/tazblog/blog/Main.hs
@@ -0,0 +1,41 @@
+-- | Main module for the blog's web server
+module Main where
+
+import           BlogDB              (initialBlogState)
+import           Control.Applicative (pure, (<$>), (<*>))
+import           Control.Exception   (bracket)
+import           Data.Acid
+import           Data.Acid.Remote
+import           Data.Word           (Word16)
+import           Locales             (version)
+import           Network             (HostName, PortID (..))
+import           Options
+import           Server
+
+data MainOptions = MainOptions {
+  dbHost      :: String,
+  dbPort      :: Word16,
+  blogPort    :: Int,
+  resourceDir :: String
+}
+
+instance Options MainOptions where
+  defineOptions = pure MainOptions
+    <*> 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/static"
+        "Resources folder location."
+
+main :: IO()
+main = do
+    putStrLn ("TazBlog " ++ version ++ " in Haskell starting")
+    runCommand $ \opts _ ->
+      let port = PortNumber $ fromIntegral $ dbPort opts
+      in openRemoteState skipAuthenticationPerform (dbHost opts) port >>=
+              (\acid -> runBlog acid (blogPort opts) (resourceDir opts))
+
+