Rename pandoc-cgi -> pandoc-server.
This commit is contained in:
parent
4359e60b93
commit
2b30d27669
5 changed files with 53 additions and 17 deletions
2
.github/workflows/release-candidate.yml
vendored
2
.github/workflows/release-candidate.yml
vendored
|
@ -20,7 +20,7 @@ jobs:
|
|||
mkdir linux-release-candidate
|
||||
cp linux/artifacts/*.deb linux-release-candidate/
|
||||
cp linux/artifacts/*.tar.gz linux-release-candidate/
|
||||
cp linux/artifacts/pandoc-cgi linux-release-candidate/
|
||||
cp linux/artifacts/pandoc-server linux-release-candidate/
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: linux-release-candidate
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
module Main where
|
||||
|
||||
import PandocCGI (app)
|
||||
import Network.Wai.Handler.CGI (run)
|
||||
import Network.Wai.Middleware.Timeout (timeout)
|
||||
|
||||
main :: IO ()
|
||||
main = run $ timeout 2 app
|
16
pandoc.cabal
16
pandoc.cabal
|
@ -428,8 +428,8 @@ flag lua53
|
|||
Description: Embed Lua 5.3 instead of 5.4.
|
||||
Default: False
|
||||
|
||||
flag pandoc-cgi
|
||||
Description: Build pandoc-cgi executable.
|
||||
flag server
|
||||
Description: Build pandoc-server executable.
|
||||
Default: False
|
||||
|
||||
flag nightly
|
||||
|
@ -789,19 +789,21 @@ executable pandoc
|
|||
buildable: True
|
||||
other-modules: Paths_pandoc
|
||||
|
||||
executable pandoc-cgi
|
||||
executable pandoc-server
|
||||
import: common-executable
|
||||
main-is: Main.hs
|
||||
other-modules: PandocCGI
|
||||
hs-source-dirs: pandoc-cgi
|
||||
if flag(pandoc-cgi)
|
||||
other-modules: PandocServer
|
||||
hs-source-dirs: server
|
||||
if flag(server)
|
||||
build-depends: base,
|
||||
pandoc,
|
||||
aeson,
|
||||
text,
|
||||
servant-server,
|
||||
wai >= 0.3,
|
||||
wai-extra >= 3.0.24
|
||||
wai-extra >= 3.0.24,
|
||||
warp,
|
||||
optparse-applicative
|
||||
|
||||
buildable: True
|
||||
else
|
||||
|
|
42
server/Main.hs
Normal file
42
server/Main.hs
Normal file
|
@ -0,0 +1,42 @@
|
|||
module Main where
|
||||
|
||||
import PandocServer (app)
|
||||
import qualified Network.Wai.Handler.CGI as CGI
|
||||
import qualified Network.Wai.Handler.Warp as Warp
|
||||
import Network.Wai.Middleware.Timeout (timeout)
|
||||
import System.Environment (getProgName)
|
||||
import Options.Applicative
|
||||
|
||||
data Opts = Opts
|
||||
{ optPort :: Warp.Port,
|
||||
optTimeout :: Int } -- in seconds
|
||||
|
||||
options :: Parser Opts
|
||||
options = Opts
|
||||
<$> option auto
|
||||
( long "port"
|
||||
<> value 3030
|
||||
<> metavar "PORT"
|
||||
<> help "Port to serve on" )
|
||||
<*> option auto
|
||||
( long "timeout"
|
||||
<> value 2
|
||||
<> metavar "SECONDS"
|
||||
<> help "Seconds timeout" )
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
progname <- getProgName
|
||||
let optspec = info (options <**> helper)
|
||||
( fullDesc
|
||||
<> progDesc "Run a pandoc server"
|
||||
<> header "pandoc-server - text conversion server" )
|
||||
opts <- execParser optspec
|
||||
|
||||
let port = optPort opts
|
||||
let app' = timeout (optTimeout opts) app
|
||||
if progname == "pandoc-server.cgi"
|
||||
then -- operate as a CGI script
|
||||
CGI.run app'
|
||||
else -- operate as a persistent server
|
||||
Warp.run port app'
|
|
@ -3,7 +3,7 @@
|
|||
{-# LANGUAGE TypeOperators #-}
|
||||
{-# LANGUAGE FlexibleContexts #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
module PandocCGI
|
||||
module PandocServer
|
||||
( app
|
||||
, Params(..)
|
||||
) where
|
Loading…
Add table
Reference in a new issue