UCW Static application

The last journal entry I made went through the process of creating a UCW server. Such a thing is quite useless by itself. This time, we’ll build a very basic application to server up static content, simple files from the hard drive. A new CLOS class is needed that inherits both the UCW:STANDARD-APPLICATION class as well as the UCW:STATIC-ROOTS-APPLICATION-MIXIN class. I’m under the impression that the STANDARD-APPLICATION is required for all UCW apps, and the other class provides the magic fu for us.

The two class options to worry about are the :URL-PREFIX and the :STATIC-ROOTS. URL-PREFIX is provided by STANDARD-APPLICATION and is how the server knows which application to use. STATIC-ROOTS is provided by the mixin and is a list of pairs, each pair is a prefix and the associated directory/file location. This example combines the users home directroy with “devel/cl/static”, so it would resolve to #P”/usr/home/thebr0x/devel/cl/static/” in my case.

(defclass static-application (standard-application static-roots-application-mixin) () (
:default-initargs :url-prefix “/static/”
:static-roots (list (cons “” (merge-pathnames “devel/cl/static/” (user-homedir-pathname))))))
That’s most of the work right there, all that’s left is to create an instance of this new class and register it with the server.

(defparameter *static-ucw-application* (make-instance ‘static-application))
(register-application *ucw-server* *static-ucw-application*)
We now have a way of providing static content from the file system to the client. I personally find this useful for things like images, css files, and javascript/ecmascript files.


Last modified on August 14, 2012. This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published.