From 2bad9a9aa4eeb6cd63eef53422751ce5fd307c6b Mon Sep 17 00:00:00 2001 From: Albert Krewinkel Date: Tue, 27 Sep 2022 11:25:54 +0200 Subject: pandoc-cli: Avoid the CPP language extension Alternative behavior for the *server* flag is implemented by using separate modules. --- pandoc-cli/server/PandocCLI/Server.hs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pandoc-cli/server/PandocCLI/Server.hs (limited to 'pandoc-cli/server') diff --git a/pandoc-cli/server/PandocCLI/Server.hs b/pandoc-cli/server/PandocCLI/Server.hs new file mode 100644 index 000000000..ce9b4e8d0 --- /dev/null +++ b/pandoc-cli/server/PandocCLI/Server.hs @@ -0,0 +1,32 @@ +{-# LANGUAGE OverloadedStrings #-} +{- | + Module : Main + Copyright : © 2006-2022 John MacFarlane + License : GPL-2.0-or-later + Maintainer : John MacFarlane + +Functions for the pandoc server CLI. +-} +module PandocCLI.Server + ( runCGI + , runServer + ) +where +import qualified Network.Wai.Handler.CGI as CGI +import qualified Network.Wai.Handler.Warp as Warp +import Network.Wai.Middleware.Timeout (timeout) +import Safe (readDef) +import System.Environment (lookupEnv) +import Text.Pandoc.Server (ServerOpts(..), parseServerOpts, app) + +-- | Runs the CGI server. +runCGI :: IO () +runCGI = do + cgiTimeout <- maybe 2 (readDef 2) <$> lookupEnv "PANDOC_SERVER_TIMEOUT" + CGI.run (timeout cgiTimeout app) + +-- | Runs the HTTP server. +runServer :: IO () +runServer = do + sopts <- parseServerOpts + Warp.run (serverPort sopts) (timeout (serverTimeout sopts) app) -- cgit v1.2.3