[web-devel] IDEA: wai-vhost

Michael Snoyman michael at snoyman.com
Tue Nov 23 11:59:24 CET 2010

Just thought I'd throw out an idea I've been bouncing around and see
if anyone would be interested in either using or implementing it.
Basically, it allows multiple WAI applications to be run as a single
app and switch which app responds to a request based upon the Host,
the same way virtual hosting works in web servers like nginx, Apache
or lighttpd. I would imagine the type signature would look something

vhost :: [(String, Application)] -> Application -> Application

The first argument would be a list of applications and their
respective virtual hosts (this would probably be better as a Map for
performance, kind of irrelevant at this point). The second argument
would be the default application to run when none of the vhosts match.
This could even just be an app that always returns a 404. It returns a
new application handles all of this transparently.

I can see two immediate uses:

* Instead of running a whole bunch of WAI fastcgi processes on a
server, you could run just a single process that automatically deals
out requests to the right app. This would save on memory usage,
especially when your apps are all sharing the same Haskell libraries.

* Instead of needing a dedicated web server like nginx to handle
vhosting, you could use the Snap handler with this and be running a
pure Haskell stack. Advantage would be easier maintenance, plus better
performance from cutting out the middleman.

At this point, it's just an idea. I don't think it's hard to
implement, but I wouldn't mind some feedback first. And if someone
else wants to take a crack at it, please speak up! I wouldn't mind
having one less package to maintain.


More information about the web-devel mailing list