This is a very simple question: How do I run a Yesod application that can handle multiple hosts at the same time?
A default Yesod setup can handle incoming connections from any host, but all URLs are rendered with approot
prepended to them. Overriding joinPath
in the Yesod instance declaration would be possible, if there was a way of storing the current domain so that it is available to that function, but there is not.
The method described on this wiki page works, but is very hackish, since it forces routes to take an additional domain
parameter (since I don't have a static set of domains to match against). For practical purposes (because I have a lot of routes, some of which are domain-independent), it would be better to have a solution that left routes untouched, since it's possible to still get the host name from the WAI request info inside of a handler function.
I use things that require absolute URLs (e.g. email, RSS, XML APIs) so approot _ = ""
is not an option.
I don't and can't know all of the host names, that need to be supported, at compile-time.
So, how do I render URLs so that they use the host name of the incoming request, and not the approot
variable?