Skip to content

Commit

Permalink
have defaults for method and status
Browse files Browse the repository at this point in the history
  • Loading branch information
Zachary Juang committed Dec 5, 2024
1 parent dde5dc6 commit 3ccd84a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/Lib/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import Network.HTTP.Types.Status
type Paths = Map String PathConfig

data PathConfig = PathConfig
{ responseMethod :: HTTPMethod
, responseStatus :: !HTTPStatus
{ responseMethod :: !(Maybe HTTPMethod)
, responseStatus :: !(Maybe HTTPStatus)
, responseDelay :: !(Maybe Int)
, responseBody :: !(Maybe Value)
, responseHeaders :: !(Maybe (Map TL.Text TL.Text))
Expand All @@ -27,8 +27,8 @@ data PathConfig = PathConfig
instance FromJSON PathConfig where
parseJSON = withObject "PathConfig" $ \o ->
PathConfig
<$> o .: "method"
<*> o .: "status"
<$> o .:? "method"
<*> o .:? "status"
<*> o .:? "delay"
<*> o .:? "body"
<*> o .:? "headers"
Expand Down
7 changes: 5 additions & 2 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ main = do
middleware logStdoutDev

forM_ (M.toList pc) $ \(path, PathConfig{..}) -> do
addroute (unMethod responseMethod) (fromString path) $ do
status (unStatus responseStatus)
let addroute' = maybe matchAny (addroute . unMethod) responseMethod
addroute' (fromString path) $ do
case responseStatus of
Nothing -> mempty
Just s -> status $ unStatus s

case responseDelay of
Nothing -> mempty
Expand Down

0 comments on commit 3ccd84a

Please sign in to comment.