Sun, Sep 6, 2009
So if you are someone like me and interested in developing web applications in Common Lisp then you have probably come across hunchentoot by Dr Edi Weitz. Now hunchentoot is not the only common lisp web-server out there and there are those who argue against its design concepts but it is one that I have found to well suit my need. Now I will be writing a list of posts about how to go around setting up things to work for a web application, but for this post i want to talk about multiple hunchentoot instances.
As you might know lisp hosting is not abundant so must of the time you need your own server instance to run your lisp on. However instances are relatively expensive when compare to other hosting options so it might be useful if you could run multiple websites of the same server. And it turns out you can do exactly that with hunchentoot and you do not need multiple instances of your common lisp running (I use SBCL).
Your first option is to visit Cyrus Harmon website and get his hunchentoot vhost code and run it on top of your hunchentoot. The code is clean and understandable and last i checked Cyrus uploaded a new version on 12 June 2009.
Your second option is to use hunchentoot built in capabilities and separate your websites on different ports (you could use a webproxy in front but that is another post). Start by creating your hunchentoot instance in the following manner:
(hunchentoot:start (make-instance ‘hunchentoot:acceptor
Now the important part is that we started by telling this particular instance that we need hunchentoot to listen to the designated port. The key thing you need to take care of however is the parameter request-dispatcher. It turns out creating a hunchentoot acceptor this way you can no longer use any of hunchentoot built in dispatcher functionality (Which is the price you have to pay). So how to deal with that is to make sure that the dispatcher is actually a function that return the appropriate html.
This function needs to take one argument which is the response object and then return the proper html based on the response. There are different ways to do this that could be fast. One suggestion which I implemented was to create a hash table with the url as the key and the handler function as the value and i simply do a funcall on the handler function. it is that simple .
Hope you enjoyed the above and stay tuned for some more information on lisp programming.