(: Aiche Tee Tee Pee :)
Perhaps the first webserver in Tree Calculus? Sure, it's married to a Haskell IO runtime... but we're managing all of the actual webserver semantics in tricu! This includes a demo Arboricx application server that is capable of storing and serving bundles.
This commit is contained in:
42
src/Main.hs
42
src/Main.hs
@@ -2,7 +2,6 @@ module Main where
|
||||
|
||||
import ContentStore (initContentStoreWithPath, loadEnvironment, loadTerm, loadTree, resolveExportTarget)
|
||||
import System.Exit (die)
|
||||
import Server (runServerWithPath)
|
||||
import Eval (evalTricu, evalTricuWithStore, mainResult, result)
|
||||
import FileEval (evaluateFileWithContext, evaluateFileWithStore, compileFile)
|
||||
import IODriver (IOPermissions(..), runIO)
|
||||
@@ -61,11 +60,6 @@ data TricuArgs
|
||||
, exportDb :: Maybe FilePath
|
||||
, dag :: Bool
|
||||
}
|
||||
| ArboricxServe
|
||||
{ serveHost :: String
|
||||
, servePort :: Int
|
||||
, serveDb :: Maybe FilePath
|
||||
}
|
||||
deriving (Show)
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -209,28 +203,6 @@ exportParser = ArboricxExport
|
||||
<> help "Export as a topologically-sorted DAG node table instead of a bundle"
|
||||
)
|
||||
|
||||
serveParser :: Parser TricuArgs
|
||||
serveParser = ArboricxServe
|
||||
<$> option str
|
||||
( long "host"
|
||||
<> metavar "HOST"
|
||||
<> value "127.0.0.1"
|
||||
<> help "Host to bind the server to"
|
||||
)
|
||||
<*> option auto
|
||||
( long "port"
|
||||
<> short 'p'
|
||||
<> metavar "PORT"
|
||||
<> value 8787
|
||||
<> help "HTTP port to listen on"
|
||||
)
|
||||
<*> optional (option str
|
||||
( long "db"
|
||||
<> short 'd'
|
||||
<> metavar "PATH"
|
||||
<> help "Content store database path"
|
||||
))
|
||||
|
||||
versionStr :: String
|
||||
versionStr = "tricu " ++ showVersion version
|
||||
|
||||
@@ -253,8 +225,6 @@ arboricxParser = subparser $ mconcat
|
||||
(progDesc "Import an Arboricx bundle into the content store"))
|
||||
, command "export" (info (exportParser <**> helper)
|
||||
(progDesc "Export one or more terms from the content store"))
|
||||
, command "serve" (info (serveParser <**> helper)
|
||||
(progDesc "Start a read-only HTTP server for Arboricx bundles"))
|
||||
]
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
@@ -274,7 +244,7 @@ main = do
|
||||
ArboricxCompile {} -> runCompile args
|
||||
ArboricxImport {} -> runImport args
|
||||
ArboricxExport {} -> runExport args
|
||||
ArboricxServe {} -> runServe args
|
||||
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Command runners
|
||||
@@ -395,16 +365,6 @@ runExportDag opts = do
|
||||
[] -> die "tricu arboricx export --dag: exactly one --target is required"
|
||||
_ -> die "tricu arboricx export --dag: exactly one --target is required"
|
||||
|
||||
runServe :: TricuArgs -> IO ()
|
||||
runServe opts = do
|
||||
let hostStr = serveHost opts
|
||||
portNum = servePort opts
|
||||
putStrLn $ "Starting Arboricx bundle server on " ++ hostStr ++ ":" ++ show portNum
|
||||
putStrLn $ " GET /bundle/hash/:hash -- primary endpoint"
|
||||
putStrLn $ " GET /bundle/name/:name -- convenience endpoint"
|
||||
putStrLn $ " Content-Type: application/vnd.arboricx.bundle"
|
||||
runServerWithPath (serveDb opts) hostStr portNum
|
||||
|
||||
-- ---------------------------------------------------------------------------
|
||||
-- Helpers
|
||||
-- ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user