monadServ guts
Here's the guts of my monadServ json based web app framework.
runRequest' :: String -> String -> st -> InternalServerState st bst -> Maybe String -> IO (String,st)
runRequest' rqBody u st iss@(InternalServerState {backendState = bst, config = config', backendService = bservice}) mfunction = do
runSrv st (outputString bservice bst Nothing) (beforePrompt config')
case lookup u (serverCommands config') of
Just f -> executeCommand u st f
Nothing -> serveContent u st
where executeCommand url' st' f = do
runSrv st' (outputString bservice bst Nothing) (srvPutStrLn $ "--- url[" ++ url' ++ "]")
let parseResult= JSON.parse rqBody
(st'', x) <- runSrvSpecial st' parseResult (outputString bservice bst Nothing) (f config')
case x of
Just res -> do
let parseResult = renderStyle (style {mode=OneLineMode}) (JSON.toDoc res)
parseResult' = case mfunction of
Just function -> function ++"("++parseResult ++");"
Nothing -> parseResult
runSrv st' (outputString bservice bst Nothing) (srvPutStrLn parseResult')
return (parseResult', st'')
Nothing -> do
let result = " returns no JSON Object."
runSrv st' (outputString bservice bst Nothing) (srvPutStrLn $ "::" ++ result)
return (result, st'')
serveContent url' st' = do
runSrv st' (outputString bservice bst Nothing) (srvPutStrLn $ " [" ++ "OP" ++"] " ++ url' ++ " --" )
let fileName= docRoot config' ++ url'
exists <- doesFileExist (fileName)
if exists
then do
let (mimetype,binary)= case DataMap.lookup (getExtension url') mimeMapping of
Nothing -> ("text/plain",False)
Just (s,b) -> (s,b)
if binary
then do
result <- ByteString.readFile (fileName)
-- (encode (unpackList result))
-- writeContent handle mimetype (octetsToString (unpackList result)) False
--writeContent handle mimetype (octetsToString (unpack result)) False
return ( octetsToString (unpack result), st')
else do
result <- System.IO.readFile (fileName)
return (result,st')
else do
return ("404 Not FOUND",st')
posted by Jeff @ 2:13 PM 0 Comments
Well this has turned into more of a personal blog. Guess that doesn't hurt to have separate site.
Just FYI for tech related articles I'm maintaining jaxclipse blog (I know not self-hosted yada yada blah blah blah). And you can help with jaxclipse.com proper if interested. Just running drupal there right now, but hope to have something more interesting in the next few weeks.
posted by Jeff @ 7:37 AM 0 Comments
Found my blog
I thought this blog was lost - It has been languishing dormant for so long. Well I guess I should at least put in a link to our web album -
First Days |
posted by Jeff @ 12:45 PM 0 Comments
Foucault's Pendulum
Condie Rice vs. B. Boxer - Where was Don King? He should have done the talking head spot after the Senate Foreign Relations sham hearing today. Seriously he made some great points in a little candid spot during last summer's RNC. I guess Rice had better odds than Payton "Cut The Meat" Manning did against the Patriots. Anyway wish I could sit around all day at work with CSPAN on instead of catching morsels like Rice slamming Boxer for TKO on AM radio...
I went to MOSH with Wally, Dennis, Zach, and E.R last Saturday afternoon. They had a F.P. and I needed to look up the following quote from Umberto Eco:
..and that together we were rotating beneath the Pendulum, whose own plane never
changed direction, because up there, along the infinite extrapolation of its
wire beyond the choir ceiling, up toward the most distant galaxies, lay the Only
Fixed Point in the universe, eternally unmoving.
posted by Jeff @ 8:43 PM 0 Comments