From be1fd594b6e0c24a91b8b93c09dbaee23d2d6796 Mon Sep 17 00:00:00 2001 From: Emily Martins Date: Wed, 29 Jun 2022 10:35:34 +0200 Subject: [PATCH] update command line options --- agora-scripts/ScriptExport/API.hs | 6 +++--- agora-scripts/ScriptExport/Options.hs | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/agora-scripts/ScriptExport/API.hs b/agora-scripts/ScriptExport/API.hs index 4fb70f1..f09ffd2 100644 --- a/agora-scripts/ScriptExport/API.hs +++ b/agora-scripts/ScriptExport/API.hs @@ -35,12 +35,12 @@ import Text.Printf (printf) @since 0.2.0 -} type API = - -- /query-script/:name + -- POST /query-script/:name "query-script" :> Capture "name" Text :> ReqBody '[JSON] Aeson.Value :> Post '[JSON] Aeson.Value - -- /info + -- GET /info :<|> "info" :> Get '[JSON] ServerInfo @@ -106,5 +106,5 @@ runServer revision builders options = do printf "[info] Running 'agora-scripts' on :%d\n" (Warp.getPort settings) Servant.serve (Proxy @API) handler - & corsMiddleware + & (if options.enableCorsMiddleware then corsMiddleware else id) & Warp.runSettings settings diff --git a/agora-scripts/ScriptExport/Options.hs b/agora-scripts/ScriptExport/Options.hs index b37da56..2ea6a57 100644 --- a/agora-scripts/ScriptExport/Options.hs +++ b/agora-scripts/ScriptExport/Options.hs @@ -11,8 +11,9 @@ import Network.Wai.Handler.Warp qualified as Warp import Options.Applicative ((<**>)) import Options.Applicative qualified as Opt -newtype Options = Options +data Options = Options { port :: Warp.Port + , enableCorsMiddleware :: Bool } deriving stock (Show, Eq) @@ -25,7 +26,18 @@ opt = <> Opt.short 'p' <> Opt.metavar "PORT" <> 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