diff --git a/app/Main.hs b/app/Main.hs index dfc87c9..b57835a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,31 +1,6 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE ScopedTypeVariables #-} - module Main where -import API.AppServices as AppServices -import API.Application (app) -import API.Config (Port (..), apiPort) -import qualified API.Config as Config -import CLIOptions (CLIOptions (configPath)) -import qualified CLIOptions -import Dependencies (Deps (..)) -import qualified Dependencies as Deps -import qualified Infrastructure.Logging.Logger as Logger -import qualified Middleware -import qualified Network.Wai.Handler.Warp as Warp -import qualified Tagger.JSONWebKey as JWK +import App main :: IO () -main = do - options <- CLIOptions.parse - appConfig <- Config.load $ configPath options - key <- JWK.setup options - - Deps.withDeps appConfig $ \Deps {dbHandle, loggerHandle} -> do - let (Port port) = apiPort . Config.api $ appConfig - services = AppServices.start dbHandle loggerHandle key - application = Middleware.apply (app services) - - Logger.logInfo loggerHandle $ "Starting app on port " <> show port <> "." - Warp.run port application +main = run diff --git a/package.yaml b/package.yaml index b16fcc6..7b5753a 100644 --- a/package.yaml +++ b/package.yaml @@ -46,6 +46,9 @@ dependencies: - transformers - uuid - wai + - wai-cors + - wai-extra + - warp executables: servant-template-exe: @@ -53,13 +56,6 @@ executables: main: Main.hs dependencies: - servant-template - - bytestring - - hasql - - jose - - transformers - - wai-cors - - wai-extra - - warp tests: servant-template-spec: diff --git a/servant-template.cabal b/servant-template.cabal index 057009d..1fe549c 100644 --- a/servant-template.cabal +++ b/servant-template.cabal @@ -23,7 +23,9 @@ library API.Docs API.Healthcheck API.Tagger + App CLIOptions + Dependencies Impl.Authentication.Authenticator Impl.Repository.Content Impl.Repository.Content.InMemory @@ -40,6 +42,7 @@ library Infrastructure.Persistence.Schema Infrastructure.Persistence.Serializer Infrastructure.SystemTime + Middleware Tagger.Authentication.Authenticator Tagger.Authentication.Credentials Tagger.Content @@ -86,13 +89,14 @@ library , transformers , uuid , wai + , wai-cors + , wai-extra + , warp default-language: Haskell2010 executable servant-template-exe main-is: Main.hs other-modules: - Dependencies - Middleware Paths_servant_template hs-source-dirs: app @@ -180,5 +184,7 @@ test-suite servant-template-spec , transformers , uuid , wai + , wai-cors + , wai-extra , warp default-language: Haskell2010 diff --git a/src/App.hs b/src/App.hs new file mode 100644 index 0000000..5329df5 --- /dev/null +++ b/src/App.hs @@ -0,0 +1,31 @@ +{-# LANGUAGE NamedFieldPuns #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module App where + +import API.AppServices as AppServices +import API.Application (app) +import API.Config (Port (..), apiPort) +import qualified API.Config as Config +import CLIOptions (CLIOptions (configPath)) +import qualified CLIOptions +import Dependencies (Deps (..)) +import qualified Dependencies as Deps +import qualified Infrastructure.Logging.Logger as Logger +import qualified Middleware +import qualified Network.Wai.Handler.Warp as Warp +import qualified Tagger.JSONWebKey as JWK + +run :: IO () +run = do + options <- CLIOptions.parse + appConfig <- Config.load $ configPath options + key <- JWK.setup options + + Deps.withDeps appConfig $ \Deps {dbHandle, loggerHandle} -> do + let (Port port) = apiPort . Config.api $ appConfig + services = AppServices.start dbHandle loggerHandle key + application = Middleware.apply (app services) + + Logger.logInfo loggerHandle $ "Starting app on port " <> show port <> "." + Warp.run port application diff --git a/app/Dependencies.hs b/src/Dependencies.hs similarity index 99% rename from app/Dependencies.hs rename to src/Dependencies.hs index 13eb642..5240e5f 100644 --- a/app/Dependencies.hs +++ b/src/Dependencies.hs @@ -1,4 +1,5 @@ {-# LANGUAGE RecordWildCards #-} + module Dependencies (withDeps, Deps (..)) where import qualified API.Config as Config diff --git a/app/Middleware.hs b/src/Middleware.hs similarity index 100% rename from app/Middleware.hs rename to src/Middleware.hs