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?

2 Answers 2

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>"))
2
  • 1
    Just chucked that in and it works sweet. How did you get that from the documentation?
    – mobydick
    Nov 28, 2011 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. Nov 28, 2011 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.