Skip to content

Commit

Permalink
better help and response type
Browse files Browse the repository at this point in the history
  • Loading branch information
zachary822 committed Dec 26, 2024
1 parent 34314a0 commit 472344c
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import Control.Monad.IO.Class
import Data.Aeson
import Data.ByteString (ByteString)
import Data.Foldable (sequenceA_, traverse_)
import Data.Functor
import Data.Map.Strict qualified as M
import Data.Maybe (catMaybes)
import Data.String
import Data.Text.Lazy qualified as TL
import Lib.Types
import Network.Wai.Middleware.Cors
import Network.Wai.Middleware.RequestLogger
Expand All @@ -36,16 +38,19 @@ configParser =
<> metavar "PORT"
<> showDefault
<> value 3000
<> help "listening port"
)
<*> strOption
( long "config"
<> short 'c'
<> metavar "FILE"
<> help "config file path"
)
<*> ( many $
strOption
( long "allowed-origin"
<> short 'a'
<> help "allowed CORS origins"
)
)

Expand Down Expand Up @@ -80,5 +85,7 @@ main = do
[ liftIO . threadDelay <$> responseDelay
, status . unStatus <$> responseStatus
, traverse_ (uncurry addHeader) . M.toList <$> responseHeaders
, json <$> responseBody
, responseBody <&> \case
String t -> text (TL.fromStrict t)
v -> json v
]

0 comments on commit 472344c

Please sign in to comment.