Clack

Revenge of Lisp in Web

Chapter 6: Using Clack.App.Directory

English | 日本語

Clack.App.Directory is a real example of a Clack application using <component>. This application serves a directory as a HTML page.

Using this application is pretty easy.

;; mount /Users/nitro_idiot/ to http://localhost:5000/
(clack:clackup
 (make-instance 'clack.app.directory:<clack-app-directory>
    :root #p"/Users/nitro_idiot/")
 :port 5000)

Then, files in "/Users/nitro_idiot/" would appear at http://localhost:5000/.

Can you see why this application uses <component> not just a function? It takes :root when making a new instance and the behavior will be changed the value. It is difficult when this application is implemented as a function.

I know it can be a function returns a closure, but it would be complicated. And there is another advantage of using Classes. -- Inheritance. To tell the truth, <clack-app-directory> doesn't inherit <component> directly. It inehrits <clack-app-file> which is an application serves just a file (not directory). What <clack-app-directory> do is only enabling to see a list of files in a directory.

If you are curious enough, core/app/directory.lisp and file.lisp which in the same directory will teach you how components is used.