Hello,
I suspect this is part of the problem. In the original you had:
main :: IO ()
main = do simpleHTTP [dir "contractEx"
[withData $ \(ExContr t) ->
[anyRequest $ liftIO $ liftM toResponse =<< renderEx (ExContr t)]
,anyRequest $ ok $ toResponse renderExDefault]
,fileServe ["Contracts.html"] "public" -- fileserving
]
Note that the 'withData' function takes a list of handlers -- and in that list there is only one handler.
The withData route will only match if valid data is submitted. If that route fails to match, then the next route is tried. In this case the next route is the second anyRequest route which will just render the default renderExDefault.
In the Happstack version:
main :: IO ()
main = do
simpleHTTP (nullConf { port = 80 }) $ msum [
dir "contractEx" $ withData $ \(ExContr t) -> msum $ [
anyRequest $ fmap toResponse $ liftIO $ renderEx (ExContr t)
, anyRequest $ toResponse renderExDefault
]
, serveDirectory DisableBrowsing ["Contracts.html"] "public"
]
Both anyRequest routes are guarded by the 'withData' function. So, neither will be called unless there is valid data. Additionally, since the first anyRequest line should always match, the second anyRequest will never be called.
The could should probably be something like:
main :: IO ()
main = do
simpleHTTP (nullConf { port = 80 }) $ msum [
dir "contractEx" $ msum $ [
withData $ \(ExContr t) -> anyRequest $ fmap toResponse $ liftIO $ renderEx (ExContr t)
, anyRequest $ toResponse renderExDefault
]
, serveDirectory DisableBrowsing ["Contracts.html"] "public"
]
So that withData is only used to guard the first anyRequest.
You can read more about routing in this chapter:
The FromData stuff is not used that commonly anymore. You can read about a more modern method of handle request data in this chapter:
- jeremy