[Haskell-beginners] Having fun with yesod, and a few questions came up.

Michael Snoyman michael at snoyman.com
Thu Jul 15 14:06:56 EDT 2010


Regarding the incompleteness of fastcgi tutorial: I'm not quite sure what
you mean. The deploying section[1] gives information on how to configure
lighttpd to run a compiled Yesod application, *not* on how to write that
application. The tutorials show you how to write a Yesod application

The only thing missing now is your other question: which handler to use. The
answer to wai-handler-fastcgi[2]. It's built on top of the libfcgi C
library, so you'll need to make sure you have that installed. A previous
version was built on the direct-fastcgi[3] package, but I found that to have
considerably lower performance. If people are interested in a
wai-handler-direct-fastcgi, let me know, I'll release it.

Anyway, the function you're probably looking for in Yesod is toWaiApp[4],
which produces an Application. You can then pass that Application to the
wai-handler-fastcgi run function, and you'll have a fastcgi executable.

If you think it will be useful, I can package up a sample application with a
lighttpd config file. And if anyone out there knows how to write config
files for other servers, that would be a nice addition as well.

Michael

[1] http://docs.yesodweb.com/yesod/deploying.html
<http://docs.yesodweb.com/yesod/deploying.html>[2]
http://hackage.haskell.org/package/wai-handler-fastcgi
[3] http://hackage.haskell.org/package/direct-fastcgi
[4] http://docs.yesodweb.com/haddock/yesod/Yesod-Dispatch.html#v%3AtoWaiApp

On Thu, Jul 15, 2010 at 8:39 PM, Michael Litchard <michael at schmong.org>wrote:

> Okay this is what I have so far, concerning what I need to do on the
> Haskell end of things to get it working with lighttpd.
>
> As an example, I will use blog.lhs from the yesod tutorial
>
> All that's left now is the main function. Yesod is built on top of
> WAI, so you can use any WAI handler you wish. For the tutorials, we'll
> use the basicHandler that comes built-in with Yesod: it serves content
> via CGI if the appropriate environment variables are available,
> otherwise with simpleserver.
>
> > main :: IO ()
> > main = do
> >   entries <- loadEntries
> >   basicHandler 3000 $ Blog entries
>
> This brings into sharp relief my ignorance on how to use hackage. I
> tried to investigate hackage looking for some WAI handler that would
> get me what I want. Namely, turning this example into a fastCGI
> application that lighttpd could use.
>
> So this generates two questions. How would one use hackage to find a
> WAI handler to use for fastCGI?
> What would be an example of a WAI handler I could use with yesod?
>
> Thanks for making it possible for guys like me to do this.
>
> On Thu, Jul 15, 2010 at 9:33 AM, Michael Snoyman <michael at snoyman.com>
> wrote:
> >
> >
> > On Thu, Jul 15, 2010 at 6:57 PM, Michael Litchard <michael at schmong.org>
> > wrote:
> >>
> >> I'm playing with yesod http://docs.yesodweb.com/yesod/,  and I have a
> >> few questions:
> >>
> >> Here's an excerpt from yesod/tutorial/i18n.lhs
> >>
> >> **NOTE: This tutorial requires the development version of Yesod
> >> (version 0.4.0). The [tutorial main page]($root/yesod/tutorial/) has
> >> instructions on setting up your environment.**
> >>
> >> Where is $root?
> >> I thought it was where yesod-examples-0.4.0 was installed. But if this
> >> is the case, I'm not finding these instructions. This makes me think I
> >> am confused about the directory $root represents.
> >>
> > Sorry about the $root stuff, it's an artifact from the web site. I use
> the
> > same code base for the yesod-examples package and the tutorials on the
> site
> > to make sure everything compiles properly. In any event, the line in
> > question is out-of-date and needs to be removed: 0.4.0 has been
> officially
> > released, so you just need a cabal install yesod to get started.
> >>
> >> I was playing around with the code and made some changes. Here is the
> >> line in question, with the complete code below for context.
> >>
> >> > instance Yesod I18N where
> >> >     approot _ = ""
> >>
> >> This does what I expect it to do, it runs the program when I open up
> >> http://my.blog.server/
> >>
> >> however, I wanted to see what would happen if I played around with it
> >> a little bit. I want the same program to run when I point my browser
> >> to http://my.blog.server/blog
> >>
> >> so I made this change
> >> >     approot _ = "/blog"
> >>
> >> but now when I point my browser to http://my.blog.server/blog it gets
> >> re-written to http:/my.blog.server/blog/blog
> >> and then this error message
> >> Not Found
> >> /blog/blog
> >>
> >> Not sure what is going on here, could someone enlighten me?
> >>
> >>
> > The approot function is used for *rendering* routes. This has no affect
> on
> > where Yesod *listens* to requests. For example, you could put approot _ =
> > "http://haskell.org", but you wouldn't be able to respond to requests
> for
> > that domain. Nonetheless, URLs generated by Yesod would then point to
> > haskell.org.
> > Basically, the only time to get fancy with approot is when you're doing
> URL
> > rewriting for (Fast)CGI hosted applications. When you use a standalone
> > server, you'll always* be serving from the root of the domain, and so the
> > value of approot should just be that domain name.
> > * Of course, there's always exceptions.
> > You might look at the documentation[1] where it explains when it's
> > permissible to use an empty string for the value of approot.
> > Michael
> > [1] http://docs.yesodweb.com/haddock/yesod/Yesod-Yesod.html#v%3Aapproot
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100715/a420df89/attachment.html


More information about the Beginners mailing list