summaryrefslogtreecommitdiff
path: root/pandoc-cli/server
diff options
context:
space:
mode:
Diffstat (limited to 'pandoc-cli/server')
-rw-r--r--pandoc-cli/server/PandocCLI/Server.hs32
1 files changed, 32 insertions, 0 deletions
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 <jgm@berkeley@edu>
+
+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)