12

The Hunchentoot documentation states:

"The method for ACCEPTOR tries to serve a static file relative to it's ACCEPTOR-DOCUMENT-ROOT."

acceptor-document-root acceptor => (or pathname null)

(setf (acceptor-document-root acceptor ) new-value)

http://weitz.de/hunchentoot/

I am having trouble in translating this documentation into actual Lisp code.

Can someone please give me an example of how to tell Hunchentoot where to look for static web pages to serve?

Community
  • 1
  • 1
mobydick
  • 151
  • 1
  • 8

2 Answers2

15

The simplest translation to code will be this:

(hunchentoot:start (make-instance 'hunchentoot:acceptor :port 4242
                                  :document-root #p"<path to static files dir>"))
Vsevolod Dyomkin
  • 9,343
  • 2
  • 31
  • 36
  • 1
    Just chucked that in and it works sweet. How did you get that from the documentation? – mobydick Nov 28 '11 at 10:28
  • 1
    The doc can be a little bit not enough explicit on that, but as it says, that there's an accessor `aceptor-document-root` in `acceptor` class, it means, that there's an appropriate slot in this class. And the convention in Lisp is to provide `initarg` for such slot named slot-name as keyword and accessors named class-slot-name. This convention is very strong and will hold in 99% of cases. – Vsevolod Dyomkin Nov 28 '11 at 12:00
11

Here is a snippet which serves a single static webpage:

(push (create-static-file-dispatcher-and-handler
       "/stylesheet.css" "~/projects/project-x/stylesheet.css")
      *dispatch-table*)

To make a whole folder available try create-folder-dispatcher-and-handler.

chrm
  • 1,258
  • 1
  • 11
  • 16