mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-06 17:52:51 -06:00
Added a preliminary "gf -server" mode.
The command "gf -server" now starts a simple HTTP server on port 41295, providing a simple web API to the GF compiler. It currently support the follwing operations: * creating new temporary directories for grammar uploads, * uploading grammars files for use in the GF shell, * executing GF shell commands, and * accessing static files. This means that GF now depends on some additional networking related packages, but they should be available and easy to install on all platforms. There is also a new configuration flag "server" in gf.cabal, so GF will be compiled without support for server mode if the extra packages are unavailable. Note that running gf -server while connected to the internet can be a security risk. To prevent unauthorized access to the rest of the system, it is advisable to run the server in GF_RESTRICTED mode and as a user with suitably restricted file permissions.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
{-# LANGUAGE ScopedTypeVariables, CPP #-}
|
||||
module GFI (mainGFI,mainRunGFI) where
|
||||
module GFI (mainGFI,mainRunGFI,mainServerGFI) where
|
||||
|
||||
import GF.Command.Interpreter
|
||||
import GF.Command.Importing
|
||||
@@ -44,6 +44,9 @@ import Control.Monad
|
||||
import Data.Version
|
||||
import Text.PrettyPrint (render)
|
||||
import GF.System.Signal
|
||||
#ifdef SERVER_MODE
|
||||
import GFServer(server)
|
||||
#endif
|
||||
--import System.IO.Error (try)
|
||||
#ifdef mingw32_HOST_OS
|
||||
import System.Win32.Console
|
||||
@@ -53,9 +56,9 @@ import System.Win32.NLS
|
||||
import Paths_gf
|
||||
|
||||
mainRunGFI :: Options -> [FilePath] -> IO ()
|
||||
mainRunGFI opts files = do
|
||||
let opts1 = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet})) opts
|
||||
shell opts1 files
|
||||
mainRunGFI opts files = shell (beQuiet opts) files
|
||||
|
||||
beQuiet = addOptions (modifyFlags (\f -> f{optVerbosity=Quiet}))
|
||||
|
||||
mainGFI :: Options -> [FilePath] -> IO ()
|
||||
mainGFI opts files = do
|
||||
@@ -64,6 +67,15 @@ mainGFI opts files = do
|
||||
|
||||
shell opts files = loop opts =<< importInEnv emptyGFEnv opts files
|
||||
|
||||
#ifdef SERVER_MODE
|
||||
mainServerGFI opts0 files =
|
||||
server (execute1 opts) =<< importInEnv emptyGFEnv opts files
|
||||
where opts = beQuiet opts0
|
||||
#else
|
||||
mainServerGFI opts files =
|
||||
error "GF has not been compiled with server mode support"
|
||||
#endif
|
||||
|
||||
-- | Read end execute commands until it is time to quit
|
||||
loop :: Options -> GFEnv -> IO ()
|
||||
loop opts gfenv = maybe (return ()) (loop opts) =<< readAndExecute1 opts gfenv
|
||||
|
||||
Reference in New Issue
Block a user