mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 11:42:49 -06:00
pgf-http now uses $datadir/www instead of ./www as the document root
Along with the changes to Setup.hs it should now be enough to do cabal install pgf-http open http://localhost:41296/ to run the PGF service locally and play with some example grammars in minibar.
This commit is contained in:
@@ -2,23 +2,34 @@
|
|||||||
import Network.CGI(requestMethod,getVarWithDefault,logCGI,handleErrors,liftIO)
|
import Network.CGI(requestMethod,getVarWithDefault,logCGI,handleErrors,liftIO)
|
||||||
import System.Environment(getArgs)
|
import System.Environment(getArgs)
|
||||||
import System.Directory(getDirectoryContents)
|
import System.Directory(getDirectoryContents)
|
||||||
import System.FilePath(takeExtension,takeFileName,takeDirectory)
|
import System.FilePath(takeExtension,takeFileName,takeDirectory,(</>))
|
||||||
|
|
||||||
import RunHTTP(runHTTP)
|
import RunHTTP(runHTTP,Options(..))
|
||||||
import ServeStaticFile(serveStaticFile)
|
import ServeStaticFile(serveStaticFile)
|
||||||
import PGFService(cgiMain',getPath,stderrToFile,logFile,newPGFCache)
|
import PGFService(cgiMain',getPath,stderrToFile,logFile,newPGFCache)
|
||||||
import FastCGIUtils(outputJSONP,handleCGIErrors)
|
import FastCGIUtils(outputJSONP,handleCGIErrors)
|
||||||
|
|
||||||
|
import Paths_gf_server(getDataDir)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do stderrToFile logFile
|
main = do datadir <- getDataDir
|
||||||
|
let defaults = Options { documentRoot = datadir</>"www",
|
||||||
|
port = 41296 }
|
||||||
cache <- newPGFCache
|
cache <- newPGFCache
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
port <- case args of
|
options <- case args of
|
||||||
[] -> return 41296
|
[] -> return defaults
|
||||||
[port] -> readIO port
|
[port] -> do p <- readIO port
|
||||||
httpMain cache port
|
return defaults{port=p}
|
||||||
|
putStrLn $ "Starting HTTP server, open http://localhost:"
|
||||||
|
++show (port options)++"/ in your web browser.\n"
|
||||||
|
print options
|
||||||
|
putStrLn $ "logFile="++logFile
|
||||||
|
stderrToFile logFile
|
||||||
|
httpMain cache options
|
||||||
|
|
||||||
httpMain cache port = runHTTP port (do log ; serve =<< getPath)
|
|
||||||
|
httpMain cache options = runHTTP options (do log ; serve =<< getPath)
|
||||||
where
|
where
|
||||||
log = do method <- requestMethod
|
log = do method <- requestMethod
|
||||||
uri <- getVarWithDefault "REQUEST_URI" "-"
|
uri <- getVarWithDefault "REQUEST_URI" "-"
|
||||||
|
|||||||
Reference in New Issue
Block a user