[web-devel] [Yesod] Re: Yesod: Dynamic subdomains

Greg Weber greg at gregweber.info
Sat Aug 27 20:56:53 CEST 2011

Great example! Inspired me to post a recipe for re-directing from www to the
main domain: http://www.yesodweb.com/show/topic/536

Did the syntax high-lighting stylesheet disappear?

The domain-based routing does make me wonder though- in Rack the data
structure is a hash instead of a record and I could place the sub-domain
somewhere in the hash. Having a reliable record is much nicer than a hash.
However, this shows a use-case where we want to save off extra data at the
WAI level, but there is no way to do so. It seems like WAI should be
modified in some way to properly accommodate this use case. The first thing
that comes to my mind is having an extra parameter in the request record
that is a Map expressly for the purpose of storing data for later use. What
do you think?

Greg Weber

On Sat, Aug 27, 2011 at 11:09 AM, Michael Snoyman <michael at snoyman.com>wrote:

> On Fri, Aug 26, 2011 at 4:09 PM, "Timo B. Hübel" <t.h at gmx.info> wrote:
> > Hi,
> >
> > I am building a Yesod web app which should support dynamic subdomains.
> > I.e. a user registers as "foobar" on http://www.example.com and can
> > afterwards access her content via http://foobar.example.com
> >
> > Is this possible at all? I am wondering, because the server name is
> > somehow hard coded in Settings.hs as approot.
> >
> > If it is possible: How do I access the domain name in a handler function?
> >
> > Thanks!
> > Timo
> Hi Timo,
> I've put up a cookbook recipe for domain-based routing[1]. It doesn't
> require checking domain names in the handler function at all, but
> instead uses the normal routing mechanism in Yesod. As a direct answer
> to your question, to get access to the domain name, you'll want to get
> the WAI request value via waiRequest[2] and then lookup the "Host"
> header in requestHeaders[3].
> Let's direct any follow-up discussion to the Yesod mailing list (CCed).
> Michael
> [1] http://www.yesodweb.com/wiki/Domain-based%20routing
> [2]
> http://hackage.haskell.org/packages/archive/yesod-core/
> [3]
> http://hackage.haskell.org/packages/archive/wai/0.4.1/doc/html/Network-Wai.html#v:requestHeaders
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110827/2dfbe012/attachment.htm>

More information about the web-devel mailing list