diff options
author | Ben Sima <ben@bsima.me> | 2020-04-10 17:49:01 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-04-10 18:23:38 -0700 |
commit | 76112b8bd26c0e282d5479ccae9d79c4dc28c35d (patch) | |
tree | 7c3343bae164552efeaed3665c7b7f1a03e825bf /Com/MusicMeetsComics/Server/Init.hs | |
parent | 61e21346a6947327bf5394f6c73499621c494986 (diff) |
Replace Config/Init/Logger with envy and simpler code
Idk what I was thinking, I dodn't need any of that stuff.
Diffstat (limited to 'Com/MusicMeetsComics/Server/Init.hs')
-rw-r--r-- | Com/MusicMeetsComics/Server/Init.hs | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/Com/MusicMeetsComics/Server/Init.hs b/Com/MusicMeetsComics/Server/Init.hs deleted file mode 100644 index 04ddc88..0000000 --- a/Com/MusicMeetsComics/Server/Init.hs +++ /dev/null @@ -1,49 +0,0 @@ -{-# LANGUAGE OverloadedStrings #-} -{-# LANGUAGE NoImplicitPrelude #-} -module Com.MusicMeetsComics.Server.Init where - -import qualified Com.MusicMeetsComics.Server.Config as Config -import Control.Concurrent (killThread) -import Control.Exception (bracket) -import qualified Control.Monad.Metrics as M -import qualified Katip -import Lens.Micro ((^.)) -import Network.Wai (Application, Middleware) -import Network.Wai.Handler.Warp (run) -import Network.Wai.Metrics (metrics, registerWaiMetrics) -import Network.Wai.Middleware.Gzip -import Protolude -import qualified System.IO as IO - --- | An action that creates a WAI 'Application' together with its resources, --- runs it, and tears it down on exit -runApp :: (Config.Config -> Application) -> IO () -runApp app = bracket Config.acquire shutdown jog - where - say = IO.hPutStrLn IO.stderr - jog config = do - say $ "hero" - say $ "port: " ++ show (Config.configPort config) - run (Config.configPort config) =<< initialize app config - --- | The 'initialize' function accepts the required environment information, --- initializes the WAI 'Application' and returns it -initialize :: (Config.Config -> Application) -> Config.Config -> IO Application -initialize app cfg = do - waiMetrics <- registerWaiMetrics (Config.configMetrics cfg ^. M.metricsStore) - let logger = Config.setLogger (Config.configEnv cfg) - -- generateJavaScript - pure . logger . metrics waiMetrics . app $ cfg - -compress :: Middleware -compress = gzip def { gzipFiles = GzipCompress } - --- | Takes care of cleaning up 'Config.Config' resources -shutdown :: Config.Config -> IO () -shutdown cfg = do - _ <- Katip.closeScribes (Config.configLogEnv cfg) - -- Monad.Metrics does not provide a function to destroy metrics store - -- so, it'll hopefully get torn down when async exception gets thrown - -- at metrics server process - killThread (Config.configEkgServer cfg) - pure () |