mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
Add flag --document-root for user with gf --server
This can make it easier to test cloud service updates before installing them.
This commit is contained in:
@@ -75,7 +75,7 @@ errors = fail . unlines
|
|||||||
-- Types
|
-- Types
|
||||||
|
|
||||||
data Mode = ModeVersion | ModeHelp | ModeInteractive | ModeRun | ModeCompiler
|
data Mode = ModeVersion | ModeHelp | ModeInteractive | ModeRun | ModeCompiler
|
||||||
| ModeServer Int{-port-}
|
| ModeServer {-port::-}Int
|
||||||
deriving (Show,Eq,Ord)
|
deriving (Show,Eq,Ord)
|
||||||
|
|
||||||
data Verbosity = Quiet | Normal | Verbose | Debug
|
data Verbosity = Quiet | Normal | Verbose | Debug
|
||||||
@@ -152,6 +152,7 @@ data Flags = Flags {
|
|||||||
optGFODir :: Maybe FilePath,
|
optGFODir :: Maybe FilePath,
|
||||||
optOutputDir :: Maybe FilePath,
|
optOutputDir :: Maybe FilePath,
|
||||||
optGFLibPath :: Maybe FilePath,
|
optGFLibPath :: Maybe FilePath,
|
||||||
|
optDocumentRoot :: Maybe FilePath, -- For --server mode
|
||||||
optRecomp :: Recomp,
|
optRecomp :: Recomp,
|
||||||
optProbsFile :: Maybe FilePath,
|
optProbsFile :: Maybe FilePath,
|
||||||
optRetainResource :: Bool,
|
optRetainResource :: Bool,
|
||||||
@@ -249,6 +250,7 @@ defaultFlags = Flags {
|
|||||||
optGFODir = Nothing,
|
optGFODir = Nothing,
|
||||||
optOutputDir = Nothing,
|
optOutputDir = Nothing,
|
||||||
optGFLibPath = Nothing,
|
optGFLibPath = Nothing,
|
||||||
|
optDocumentRoot = Nothing,
|
||||||
optRecomp = RecompIfNewer,
|
optRecomp = RecompIfNewer,
|
||||||
optProbsFile = Nothing,
|
optProbsFile = Nothing,
|
||||||
optRetainResource = False,
|
optRetainResource = False,
|
||||||
@@ -292,6 +294,8 @@ optDescr =
|
|||||||
Option [] ["run"] (NoArg (mode ModeRun)) "Run in interactive mode, showing output only (no other messages).",
|
Option [] ["run"] (NoArg (mode ModeRun)) "Run in interactive mode, showing output only (no other messages).",
|
||||||
Option [] ["server"] (OptArg modeServer "port") $
|
Option [] ["server"] (OptArg modeServer "port") $
|
||||||
"Run in HTTP server mode on given port (default "++show defaultPort++").",
|
"Run in HTTP server mode on given port (default "++show defaultPort++").",
|
||||||
|
Option [] ["document-root"] (ReqArg gfDocuRoot "DIR")
|
||||||
|
"Overrides the default document root for --server mode.",
|
||||||
Option [] ["tags"] (NoArg (set $ \o -> o{optMode = ModeCompiler, optTagsOnly = True})) "Build TAGS file and exit.",
|
Option [] ["tags"] (NoArg (set $ \o -> o{optMode = ModeCompiler, optTagsOnly = True})) "Build TAGS file and exit.",
|
||||||
Option ['E'] [] (NoArg (phase Preproc)) "Stop after preprocessing (with --preproc).",
|
Option ['E'] [] (NoArg (phase Preproc)) "Stop after preprocessing (with --preproc).",
|
||||||
Option ['C'] [] (NoArg (phase Convert)) "Stop after conversion to .gf.",
|
Option ['C'] [] (NoArg (phase Convert)) "Stop after conversion to .gf.",
|
||||||
@@ -394,6 +398,7 @@ optDescr =
|
|||||||
lexicalCat x = set $ \o -> o { optLexicalCats = foldr Set.insert (optLexicalCats o) (splitBy (==',') x) }
|
lexicalCat x = set $ \o -> o { optLexicalCats = foldr Set.insert (optLexicalCats o) (splitBy (==',') x) }
|
||||||
outDir x = set $ \o -> o { optOutputDir = Just x }
|
outDir x = set $ \o -> o { optOutputDir = Just x }
|
||||||
gfLibPath x = set $ \o -> o { optGFLibPath = Just x }
|
gfLibPath x = set $ \o -> o { optGFLibPath = Just x }
|
||||||
|
gfDocuRoot x = set $ \o -> o { optDocumentRoot = Just x }
|
||||||
recomp x = set $ \o -> o { optRecomp = x }
|
recomp x = set $ \o -> o { optRecomp = x }
|
||||||
probsFile x = set $ \o -> o { optProbsFile = Just x }
|
probsFile x = set $ \o -> o { optProbsFile = Just x }
|
||||||
|
|
||||||
|
|||||||
@@ -71,8 +71,11 @@ shell opts files = loop opts =<< runSIO (importInEnv emptyGFEnv opts files)
|
|||||||
|
|
||||||
#ifdef SERVER_MODE
|
#ifdef SERVER_MODE
|
||||||
mainServerGFI opts0 port files =
|
mainServerGFI opts0 port files =
|
||||||
server port (execute1 opts) =<< runSIO (importInEnv emptyGFEnv opts files)
|
server port root (execute1 opts)
|
||||||
where opts = beQuiet opts0
|
=<< runSIO (importInEnv emptyGFEnv opts files)
|
||||||
|
where
|
||||||
|
root = flag optDocumentRoot opts
|
||||||
|
opts = beQuiet opts0
|
||||||
#else
|
#else
|
||||||
mainServerGFI opts files =
|
mainServerGFI opts files =
|
||||||
error "GF has not been compiled with server mode support"
|
error "GF has not been compiled with server mode support"
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ import RunHTTP(cgiHandler)
|
|||||||
debug s = logPutStrLn s
|
debug s = logPutStrLn s
|
||||||
|
|
||||||
-- | Combined FastCGI and HTTP server
|
-- | Combined FastCGI and HTTP server
|
||||||
server port execute1 state0 =
|
server port optroot execute1 state0 =
|
||||||
do --stderrToFile logFile
|
do --stderrToFile logFile
|
||||||
state <- newMVar M.empty
|
state <- newMVar M.empty
|
||||||
cache <- PS.newPGFCache
|
cache <- PS.newPGFCache
|
||||||
datadir <- getDataDir
|
datadir <- getDataDir
|
||||||
let root = datadir</>"www"
|
let root = maybe (datadir</>"www") id optroot
|
||||||
-- debug $ "document root="++root
|
-- debug $ "document root="++root
|
||||||
setCurrentDirectory root
|
setCurrentDirectory root
|
||||||
-- FCGI.acceptLoop forkIO (handle_fcgi execute1 state0 state cache)
|
-- FCGI.acceptLoop forkIO (handle_fcgi execute1 state0 state cache)
|
||||||
|
|||||||
Reference in New Issue
Block a user