Skip to content

Commit

Permalink
Merge pull request #53 from anton-k/api-tree-normal-form
Browse files Browse the repository at this point in the history
Api tree normal form
  • Loading branch information
anton-k authored Oct 24, 2023
2 parents e8978fd + 2f21c5b commit a99891d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions mig-extra/mig-extra.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ library
, bytestring
, case-insensitive
, containers
, data-default
, exceptions
, extra
, http-api-data
Expand Down
1 change: 1 addition & 0 deletions mig-extra/package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ default-extensions:

dependencies:
- base >= 4.7 && < 5
- data-default
- mig
- http-api-data
- blaze-html
Expand Down
1 change: 1 addition & 0 deletions mig-extra/src/Mig/Extra/Server/Common.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import Mig.Core hiding (

import Control.Monad.IO.Class as X
import Data.Aeson as X (FromJSON (..), ToJSON (..))
import Data.Default as X
import Data.OpenApi as X (OpenApi, ToParamSchema (..), ToSchema (..))
import Data.Text as X (Text)
import GHC.Generics as X (Generic)
Expand Down
5 changes: 2 additions & 3 deletions mig-server/src/Mig/Server/Warp.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ module Mig.Server.Warp (
CacheConfig (..),
) where

import Data.Default
import Mig.Core
import Mig.Core.Server.Cache
import Mig.Server.Wai
import Network.Wai.Handler.Warp qualified as Warp

runServer :: Int -> Server IO -> IO ()
runServer port server = Warp.run port (toApplication config server)
where
config = ServerConfig{maxBodySize = Nothing, cache = Nothing, findRoute = TreeFinder}
runServer port server = Warp.run port (toApplication def server)

runServer' :: ServerConfig -> Int -> Server IO -> IO ()
runServer' config port server = Warp.run port (toApplication config server)
8 changes: 6 additions & 2 deletions mig-wai/src/Mig/Server/Wai.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ data ServerConfig = ServerConfig
}

instance Default ServerConfig where
def = ServerConfig Nothing Nothing TreeFinder
def = ServerConfig Nothing Nothing PlainFinder

-- | Algorithm to find route handlers by path
data FindRouteType = TreeFinder | PlainFinder
data FindRouteType
= -- | converts api to tree-like structure (prefer it for servers with many routes)
TreeFinder
| -- | no optimization (prefer it for small servers)
PlainFinder

toApplication :: ServerConfig -> Server IO -> Wai.Application
toApplication config = case config.cache of
Expand Down

0 comments on commit a99891d

Please sign in to comment.