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

Michael Snoyman michael at snoyman.com
Sat Aug 27 21:10:33 CEST 2011

The stylesheet: Pandoc compiled without -fhighlighting (as we both
knew would happen eventually ;)). I'm recompiling and uploading a new
copy now.

I don't really think this has anything to do with WAI. Firstly, I was
mistaken in using the Host request header, WAI already provides a
serverName record in the Request datatype, I'd simply forgotten about
it. The routing issue is that Yesod only pays attention to the path
info for routing, so we're "hacking" WAI to expose extra information
in that record that wouldn't normally be there. I think the real
question is if Yesod needs to be modified to allow routing on
something else, but I think that:

1. We've optimized for the common case, and any deviation from what
we've done will make normal usage of Yesod much more difficult.
2. Even though this is a hack, it's not a particularly bad one, and
all normal Yesod features like type-safe URLs and declarative routing
still work without a hitch.


On Sat, Aug 27, 2011 at 9:56 PM, Greg Weber <greg at gregweber.info> wrote:
> 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

More information about the web-devel mailing list