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')

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.

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


Skippo game during one of last years hurricanes/ Posted by Hello


collage from our trip to North Carolina. Posted by Hello


Full picture used to make the avatar pic. Posted by Hello


Our living room during one of the huricanes last year... Posted by Hello


This is my favorite plant. It is very old. Don't know what it is called. Anyone know? Posted by Hello


Ode to clutter in C#minor... Posted by Hello


Two wonderful people. Posted by Hello


I love this picture Posted by Hello


so peaceful... Posted by Hello


more wonderful space Posted by Hello


Ranch in Texas. So peaceful... Posted by Hello


Nothing But Blue Skys, well sorta... Posted by Hello

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.