[Haskell-cafe] happstack file serving

Gary Klindt gary.klindt at googlemail.com
Tue Nov 1 15:48:53 CET 2011

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.
For that purpose I need to use some javascript libraries in my directory tree. I tried:

main = simpleHTTP nullConf $ msum [ serveFile (asContentType "text/html") "index.html"
				  , serveFile (asContentType "text/javascript") "javascript/js.js" ]

The js.js - file will never be found in this way because after finding the index.html,
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 called.
(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") "index.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 (javascript). Is it right that using a running
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

More information about the Haskell-Cafe mailing list