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

Michael Snoyman michael at snoyman.com
Thu Jul 15 12:33:17 EDT 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100715/4998ddc1/attachment.html


More information about the Beginners mailing list