alevy / simple

A minimal Haskell web-framework based on the WAI web server interface.
http://simple.cx
39 stars 10 forks source link

Web.Frank - Page never found #16

Closed nd2s closed 8 years ago

nd2s commented 8 years ago

Maybe I am misunderstanding something, but with simple-0.11.0, warp-3.1.12 and following code:

run 3000 $ controllerApp () $ get "/" (return $ okHtml "success")

http://localhost:3000/ always returns error 404. Using response from Web.Simple works fine, but I can't get it working with Frank.

alevy commented 8 years ago

You need to use respond instead of return:

run 3000 $ controllerApp () $ get "/" (respond $ okHtml "success")

The basic idea of any block of Controller code (Frank is just a library for the Controller monad), is that it either invokes respond (in which case the rest of the computation is not executed and an HTTP response is generated), or it returns, in which case the value of the block is taken from the argument to return.

If the top-level Controller returns, the default response is a 404.

So what you're seeing is just the default response, because your top-level controller returns rather than responds

nd2s commented 8 years ago

Ah, makes sense, and works. Thanks for the explanation!

But then the example in the documentation here seems to be wrong.

alevy commented 8 years ago

Yes! That's wrong... thanks for pointing it out!