Skip to content

Commit

Permalink
Move all the code into the library (src/) for maximum ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
cgeorgii committed Aug 30, 2023
1 parent 69c22a2 commit 0ae2cb7
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 36 deletions.
29 changes: 2 additions & 27 deletions app/Main.hs
Original file line number Diff line number Diff line change
@@ -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
10 changes: 3 additions & 7 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,16 @@ dependencies:
- transformers
- uuid
- wai
- wai-cors
- wai-extra
- warp

executables:
servant-template-exe:
source-dirs: app
main: Main.hs
dependencies:
- servant-template
- bytestring
- hasql
- jose
- transformers
- wai-cors
- wai-extra
- warp

tests:
servant-template-spec:
Expand Down
10 changes: 8 additions & 2 deletions servant-template.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ library
API.Docs
API.Healthcheck
API.Tagger
App
CLIOptions
Dependencies
Impl.Authentication.Authenticator
Impl.Repository.Content
Impl.Repository.Content.InMemory
Expand All @@ -40,6 +42,7 @@ library
Infrastructure.Persistence.Schema
Infrastructure.Persistence.Serializer
Infrastructure.SystemTime
Middleware
Tagger.Authentication.Authenticator
Tagger.Authentication.Credentials
Tagger.Content
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -180,5 +184,7 @@ test-suite servant-template-spec
, transformers
, uuid
, wai
, wai-cors
, wai-extra
, warp
default-language: Haskell2010
31 changes: 31 additions & 0 deletions src/App.hs
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/Dependencies.hs → src/Dependencies.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE RecordWildCards #-}

module Dependencies (withDeps, Deps (..)) where

import qualified API.Config as Config
Expand Down
File renamed without changes.

0 comments on commit 0ae2cb7

Please sign in to comment.