summaryrefslogtreecommitdiff
path: root/Com/MusicMeetsComics/Server.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Com/MusicMeetsComics/Server.hs')
-rw-r--r--Com/MusicMeetsComics/Server.hs62
1 files changed, 39 insertions, 23 deletions
diff --git a/Com/MusicMeetsComics/Server.hs b/Com/MusicMeetsComics/Server.hs
index 5736688..a1a9981 100644
--- a/Com/MusicMeetsComics/Server.hs
+++ b/Com/MusicMeetsComics/Server.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE OverloadedStrings #-}
+{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
@@ -16,26 +17,21 @@
-- : dep aeson
-- : dep clay
-- : dep containers
--- : dep miso
--- : dep protolude
--- : dep servant
--- : dep split
--- : dep string-quote
--- : dep text
-- : dep dhall
--- : dep ekg
--- : dep fast-logger
+-- : dep envy
-- : dep http-types
--- : dep katip
-- : dep lucid
--- : dep monad-logger
--- : dep monad-metrics
+-- : dep miso
-- : dep mtl
-- : dep network-uri
--- : dep safe
+-- : dep protolude
+-- : dep servant
-- : dep servant-lucid
-- : dep servant-server
-- : dep split
+-- : dep split
+-- : dep string-quote
+-- : dep text
-- : dep wai
-- : dep wai-app-static
-- : dep wai-extra
@@ -47,10 +43,6 @@ import qualified Clay
import Com.MusicMeetsComics.App
import qualified Com.MusicMeetsComics.Assets as Assets
import qualified Com.MusicMeetsComics.Database as Database
-import qualified Com.MusicMeetsComics.Server.Config
- as Config
-import qualified Com.MusicMeetsComics.Server.Init
- as Init
import qualified Com.MusicMeetsComics.Look as Look
import qualified Com.MusicMeetsComics.Look.Typography
as Typography
@@ -70,16 +62,41 @@ import Network.HTTP.Media ( (//)
import Network.HTTP.Types hiding ( Header )
import Network.Wai
import Network.Wai.Application.Static
+import qualified Network.Wai.Handler.Warp as Warp
import Protolude
import Servant
+import qualified System.Envy as Envy
+import qualified System.Exit as Exit
+import qualified System.IO as IO
main :: IO ()
-main = do
- db <- Database.dummy
- Init.runApp (app db)
-
-app :: Database.ComicDB -> Config.Config -> Application
+main = bracket startup shutdown run
+ where
+ say = IO.hPutStrLn IO.stderr
+ startup = Envy.decodeEnv >>= \case
+ Left e -> Exit.die e
+ Right c -> do
+ db <- Database.dummy
+ say $ "hero"
+ say $ "port: " ++ (show $ heroPort c)
+ say $ "client: " ++ heroClient c
+ return (db, c)
+ shutdown :: a -> IO a
+ shutdown = pure . identity
+ run (db, config) = Warp.run (heroPort config) (app db config)
+
+data Config = Config
+ { heroPort :: Warp.Port -- ^ HERO_PORT
+ , heroClient :: FilePath -- ^ HERO_CLIENT
+ } deriving (Generic, Show)
+
+instance Envy.DefConfig Config where
+ defConfig = Config 3000 "_bild/Com.MusicMeetsComics.Client/static"
+
+instance Envy.FromEnv Config
+
+app :: Database.ComicDB -> Config -> Application
app db cfg = serve
(Proxy @AllRoutes)
( static
@@ -89,8 +106,7 @@ app db cfg = serve
:<|> pure heroManifest
:<|> Tagged handle404
)
- where
- static = serveDirectoryWith $ defaultWebAppSettings $ Config.configClient cfg
+ where static = serveDirectoryWith $ defaultWebAppSettings $ heroClient cfg
-- | HtmlPage for setting HTML doctype and header