Hello,<br><br>I have difficulties mixing web-routes and forms:<br>I have put routes in all my site, except for forms which remains with the type ServerPartT IO Response.<br>How to make them work together?<br><br>I have:<br>
<span style="font-family: courier new,monospace;">type NomicServer = ServerPartT IO</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">type RoutedNomicServer = RouteT PlayerCommand NomicServer</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">newRule :: ServerHandle -> NomicServer Response</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">newRule sh = do</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> methodM POST -- only accept a post method</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> mbEntry <- getData -- get the data</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> case mbEntry of</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> Nothing -> error $ "error: newRule"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> Just (NewRule name text code pn) -> do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> </span><i style="color: rgb(255, 0, 0); font-family: courier new,monospace;"><b>html <- nomicPageComm pn sh (submitRule name text code pn))</b></i><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ok $ toResponse html</span><br style="font-family: courier new,monospace;"><br><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">nomicPageComm :: PlayerNumber -> ServerHandle -> Comm () -> RoutedNomicServer Html</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">nomicPageComm pn sh comm =</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">(..)</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">launchWebServer :: ServerHandle -> IO ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">launchWebServer sh = do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> putStrLn "Starting web server...\nTo connect, drive your browser to \"<a href="http://localhost:8000/Login\">http://localhost:8000/Login\</a>""</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> d <- liftIO getDataDir</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> simpleHTTP nullConf $ mconcat [dir "postLogin" $ postLogin,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> fileServe [] d,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> dir "Login" $ ok $ toResponse $ loginPage,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> dir "NewRule" $ newRule sh,</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> dir "NewGame" $ newGameWeb sh,</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> dir "Nomic" $ do</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> html <- implSite "<a href="http://localhost:8000/Nomic/">http://localhost:8000/Nomic/</a>" "" (nomicSite sh)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> ok $ toResponse html</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ]</span><br>
<br><br>The red line doesn't compile. I don't know how to transform<span style="font-family: arial,helvetica,sans-serif;"> a RoutedNomicServer into a NomicServer.</span><br><br>For the future I intend to use formlets: is these some examples of programs using happstack + web-routes + formlets?<br>
<br>Thanks,<br>Corentin<br><br><br><br><br><div class="gmail_quote">On Fri, Jan 7, 2011 at 5:10 PM, Jeremy Shaw <span dir="ltr"><<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
The [(String, String)] argument is for adding query parameters.<br>
<br>
> encodePathInfo ["foo", "bar", "baz"] [("key","value")]<br>
<br>
"foo/bar/baz?key=value"<br>
<br>
Instead of showURL you would use showURLParams.<br>
<br>
hope this helps!d<br>
- jeremy<br>
<br>
On Fri, Jan 7, 2011 at 8:12 AM, Corentin Dupont<br>
<div class="im"><<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>> wrote:<br>
</div><div><div></div><div class="h5">> Hello Jeremy,<br>
> I'm using Web routes with happstack.<br>
> I'm following this tutorial:<br>
> <a href="http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html" target="_blank">http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html</a><br>
><br>
> But It seems out of synch with the latest version of web-routes: 0.23.2.<br>
> The haddock documentation seems out of date also:<br>
><br>
> encodePathInfo :: [String] -> [(String, String)] -> String<br>
><br>
> For example:<br>
><br>
> encodePathInfo [\"foo\", \"bar\", \"baz\"]<br>
><br>
> "foo/bar/baz"<br>
><br>
> And I can't figure out what this [(String, String)] is for ;)<br>
><br>
> Thanks,<br>
><br>
> Corentin<br>
><br>
</div></div></blockquote></div><br>