Hey Antoine,

thank you for answering. Your strategy is quite similar to the one I prefer. I misunderstood the behaviour of serveDirectory. The problem with external javascript files is solved. 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 that: flatten:

module Main where

import Happstack.Server
import Control.Monad

main :: IO ()
main = simpleHTTP nullConf $
    msum [ flatten $ dir "ok" $ ok "jeahh!"
         , serveDirectory DisableBrowsing ["index.html"] "static" ]


Cheers

On 11/01/2011 03:58 PM, Antoine Latter wrote:
Hi Gary,

A convention I use in my top-level handler is:

simpleHTTP nullConf $
         msum
           [<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
then keep all of my static CSS and Javascript files in the static
directory.

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.

Antoine

On Tue, Nov 1, 2011 at 9:48 AM, Gary Klindt<gary.kli...@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.
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


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to