aboutsummaryrefslogtreecommitdiff
path: root/app/Main.hs
diff options
context:
space:
mode:
authorevuez <julien@mulga.net>2024-04-01 15:17:30 +0200
committerevuez <julien@mulga.net>2024-04-03 22:45:36 +0200
commit985974c264804ff788b3b5242fef707d4b7fa9a6 (patch)
treed80f83db178c3fd1b83b3b749793d47236dde35d /app/Main.hs
downloadwebmaild-985974c264804ff788b3b5242fef707d4b7fa9a6.tar.gz
Initial commit
Diffstat (limited to 'app/Main.hs')
-rw-r--r--app/Main.hs44
1 files changed, 44 insertions, 0 deletions
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
index 0000000..e82d838
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,44 @@
+module Main (main) where
+
+import qualified Cache
+import Control.Concurrent (forkIO)
+import qualified Http
+import Intro
+import qualified Queue as Q
+import qualified Smtp
+import System.Environment (getArgs)
+
+data Opts = Opts {httpPort :: String, smtpPort :: String} deriving (Show)
+
+defaultHttpPort :: String
+defaultHttpPort = "9785"
+
+defaultSmtpPort :: String
+defaultSmtpPort = "5879"
+
+main :: IO ()
+main = do
+ args <- getArgs
+ case (parseArgs args) of
+ Right opts -> do
+ putStrLn $ "Starting HTTP server at http://localhost:" ++ opts.httpPort
+ putStrLn $ "Starting SMTP server at smtp://localhost:" ++ opts.smtpPort
+
+ queue <- Q.newQueue
+ cache <- Cache.newInMemory
+ _ <- forkIO $ Cache.start queue cache
+ _ <- forkIO $ Http.runServer Nothing opts.httpPort cache queue
+ Smtp.runServer Nothing opts.smtpPort queue
+ Left err -> putStrLn ("Error. " ++ err)
+
+parseArgs :: [String] -> Either String Opts
+parseArgs args = parse args (Opts defaultHttpPort defaultSmtpPort)
+ where
+ parse [] opts = Right opts
+ parse (x1 : x2 : xs) opts
+ | x1 == "-http-port" = parse xs (opts{httpPort = x2})
+ | x1 == "-smtp-port" = parse xs (opts{smtpPort = x2})
+ parse (x : []) _
+ | x == "-http-port" = Left "Missing HTTP port"
+ | x == "-smtp-port" = Left "Missing SMTP port"
+ parse (x : _) _ = Left ("Unrecognized option: " ++ x)