[Haskell-cafe] happstack file serving
gary.klindt at googlemail.com
Tue Nov 1 17:24:48 CET 2011
thank you for answering. Your strategy is quite similar to the one I
prefer. I misunderstood the behaviour of serveDirectory. The problem
The other problem I had, was, that the argument 'msum' is a list, which
has elements with the same type, so I needed a conversion from
m [Char] to m Response.
In Happstack.Server.Response there is a function, which actually does
module Main where
main :: IO ()
main = simpleHTTP nullConf $
msum [ flatten $ dir "ok" $ ok "jeahh!"
, serveDirectory DisableBrowsing ["index.html"] "static" ]
On 11/01/2011 03:58 PM, Antoine Latter wrote:
> Hi Gary,
> A convention I use in my top-level handler is:
> simpleHTTP nullConf $
> [<dynamic content handler>
> , serveDirectory DisableBrowsing  "static"
> ,<404 handler>
> where 'serveDirectory' is a function that ships with happstack-server
> and serves up the contents of a directory which it is pointed at. I
> The second argument to 'serveDirectory' is used to specify the
> index-files to look for in a folder if the user browses to a static
> folder, so here you could specify "index.html" to have
> 'serveDirectory' look for files named "index.html" and serve them up
> when a top-level folder is requested.
> On Tue, Nov 1, 2011 at 9:48 AM, Gary Klindt<gary.klindt at googlemail.com> wrote:
>> Hello all,
>> I want to have a web application using one 'index.html' file with ajax
>> requests and a happstack web server which response to server requests.
>> tree. I tried:
>> main = simpleHTTP nullConf $ msum [ serveFile (asContentType "text/html")
>> , serveFile (asContentType
>> The js.js - file will never be found in this way because after finding the
>> the msum function stops (as described in the happstack crash course).
>> If I change the order, I can see the source of js.js.
>> I also tried leaving it.
>> In every case, inside index.html a function defined in js.js cannot be
>> (naturally, I sourced the file inside index.html)
>> Is it possible to obtain the effect of beeing able to call a function in an
>> external file
>> without jmacro?
>> I also tried:
>> main = simpleHTTP nullConf $ msum [ dir "ok" $ ok "jeah!"
>> , serveFile (asContentType "text/html")
>> Couldn't match expected type `[Char]' with actual type `Response'
>> Expected type: ServerPartT IO [Char]
>> Actual type: ServerPartT IO Response
>> In the return type of a call of `serveFile'
>> In the expression:
>> serveFile (asContentType "text/html") "index.html"
>> The webserver should take requests, and if there is none (no dir, personal
>> convention), it should provide index.html.
>> The error is because msum needs the same input types. Is it possible to
>> transform one of these types to the other?
>> It seems that my approach to the problem is not the right one, the one the
>> authors thought about while programming.
>> I wanted to have a clear seperation from logic (haskell) and interface
>> haskell webserver with the web application 'in it' is in general a faster
>> solution than using for example apache with
>> the fcgi module?
>> Which approach would you prefer to realize such an ajax application?
>> Greets Gary
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe