How to tell Hunchentoot where to find static web pages to serve?
Asked Answered
P

2

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?

Predicate answered 27/11, 2011 at 11:9 Comment(0)
P
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>"))
Picardi answered 27/11, 2011 at 20:17 Comment(2)
Just chucked that in and it works sweet. How did you get that from the documentation?Predicate
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.Picardi
P
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.

Papaveraceous answered 27/11, 2011 at 12:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.