Hi all,<br>I'm trying to make a web server that manages its own state. The user can issue commands that modifies the state.<br>I did like below but unfortunatly the state is not keep after a command is issued...<br>
What is the right way to do it? Is there any example sites with an internal state with happstack?<br><br><i>data Game = (the state of my game)<br>type NomicServer = ServerPartT (StateT Game IO)<br><br>launchWebServer :: Game -> IO ()<br>
launchWebServer initialState = do<br> putStrLn "Starting web server...\nTo connect, drive your browser to \"<a href="http://localhost:8000/Login%5C" target="_blank">http://localhost:8000/Login\</a>""<br>
d <- getDataDir<br> simpleHTTP' unpackStateT nullConf $ server d<br><br><br>server :: FilePath -> ServerPartT (StateT Game IO) Response<br>server d sh = mconcat [fileServe [] d, do<br> decodeBody (defaultBodyPolicy "/tmp/" 4096 4096 4096)<br>
html <- implSite "<a href="http://localhost:8000/" target="_blank">http://localhost:8000/</a>" "" nomicSite<br> return $ toResponse html]<br>
<br>
unpackStateT:: Game -> UnWebT (StateT Game IO) Response -> UnWebT IO Response<br>unpackStateT g w = evalStateT w g<br> <br>--handler for web routes<br>nomicSite :: Site PlayerCommand (NomicServer Html)<br>nomicSite = setDefault (Noop 0) Site {<br>
handleSite = \f url -> unRouteT (routedNomicCommands url) f<br> , formatPathSegments = \u -> (toPathSegments u, [])<br> , parsePathSegments = parseSegments fromPathSegments<br>}</i><br><br>Thanks a lot,<br>
Corentin