update command line options

This commit is contained in:
Emily Martins 2022-06-29 10:35:34 +02:00
parent bc501f291c
commit 519eed07b6
2 changed files with 17 additions and 5 deletions

View file

@ -35,12 +35,12 @@ import Text.Printf (printf)
@since 0.2.0 @since 0.2.0
-} -}
type API = type API =
-- /query-script/:name -- POST /query-script/:name
"query-script" "query-script"
:> Capture "name" Text :> Capture "name" Text
:> ReqBody '[JSON] Aeson.Value :> ReqBody '[JSON] Aeson.Value
:> Post '[JSON] Aeson.Value :> Post '[JSON] Aeson.Value
-- /info -- GET /info
:<|> "info" :<|> "info"
:> Get '[JSON] ServerInfo :> Get '[JSON] ServerInfo
@ -106,5 +106,5 @@ runServer revision builders options = do
printf "[info] Running 'agora-scripts' on :%d\n" (Warp.getPort settings) printf "[info] Running 'agora-scripts' on :%d\n" (Warp.getPort settings)
Servant.serve (Proxy @API) handler Servant.serve (Proxy @API) handler
& corsMiddleware & (if options.enableCorsMiddleware then corsMiddleware else id)
& Warp.runSettings settings & Warp.runSettings settings

View file

@ -11,8 +11,9 @@ import Network.Wai.Handler.Warp qualified as Warp
import Options.Applicative ((<**>)) import Options.Applicative ((<**>))
import Options.Applicative qualified as Opt import Options.Applicative qualified as Opt
newtype Options = Options data Options = Options
{ port :: Warp.Port { port :: Warp.Port
, enableCorsMiddleware :: Bool
} }
deriving stock (Show, Eq) deriving stock (Show, Eq)
@ -25,7 +26,18 @@ opt =
<> Opt.short 'p' <> Opt.short 'p'
<> Opt.metavar "PORT" <> Opt.metavar "PORT"
<> Opt.value 3939 <> Opt.value 3939
<> Opt.help "The path where the script configuration is." <> Opt.help "The port to run the server on."
)
<*> Opt.switch
( Opt.long "enable-cors-middleware"
<> Opt.short 'c'
<> Opt.help
( unwords
[ "Enable cors middleware."
, "This is usually required for some local servers."
, "For security reasons, this should be disabled in production."
]
)
) )
parseOptions :: IO Options parseOptions :: IO Options