mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-11 20:22:51 -06:00
Split pgf-server into pgf-fcgi and pgf-http.
The dependency on the fastcgi package made pgf-server difficult to compile, so
it is now split into
- pgf-fgci (main module in pgf-fcgi.hs), which is built only if fastcgi is
already installed or if you turn on the fastcgi flag (e.g. by doing
'cabal install -f fastcgi').
- pgf-http (main module in pgf-http.hs) which is always built (and hopefully
has no problematic dependencies.)
The modules FastCGIUtils and PGFService no longer depend on fastcgi.
This commit is contained in:
38
src/server/pgf-http.hs
Normal file
38
src/server/pgf-http.hs
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
import Network.CGI(requestMethod,getVarWithDefault,logCGI,handleErrors,liftIO)
|
||||
import System.Environment(getArgs)
|
||||
import System.Directory(getDirectoryContents)
|
||||
import System.FilePath(takeExtension,takeFileName,takeDirectory)
|
||||
|
||||
import RunHTTP(runHTTP)
|
||||
import ServeStaticFile(serveStaticFile)
|
||||
import PGFService(cgiMain',getPath,stderrToFile,logFile,newPGFCache)
|
||||
import FastCGIUtils(outputJSONP,handleCGIErrors)
|
||||
|
||||
main :: IO ()
|
||||
main = do stderrToFile logFile
|
||||
cache <- newPGFCache
|
||||
args <- getArgs
|
||||
port <- case args of
|
||||
[] -> return 41296
|
||||
[port] -> readIO port
|
||||
httpMain cache port
|
||||
|
||||
httpMain cache port = runHTTP port (do log ; serve =<< getPath)
|
||||
where
|
||||
log = do method <- requestMethod
|
||||
uri <- getVarWithDefault "REQUEST_URI" "-"
|
||||
logCGI $ method++" "++uri
|
||||
|
||||
serve path =
|
||||
handleErrors . handleCGIErrors $
|
||||
if takeExtension path==".pgf"
|
||||
then cgiMain' cache path
|
||||
else if takeFileName path=="grammars.cgi"
|
||||
then grammarList (takeDirectory path)
|
||||
else serveStaticFile path
|
||||
|
||||
grammarList dir =
|
||||
do paths <- liftIO $ getDirectoryContents dir
|
||||
let pgfs = [path|path<-paths, takeExtension path==".pgf"]
|
||||
outputJSONP pgfs
|
||||
Reference in New Issue
Block a user