common-lisphunchentoot

easy-acceptor ignoring :document-root option; not serving static files


I am trying to serve static files with Hunchentoot, from the www directory inside my project. My acceptor is defined as:

(defvar *acceptor* (make-instance 'easy-acceptor
        :port 4242
        :document-root (truename "./www/")))

I then start it with:

(start *acceptor*)

The acceptor works, in that I can use define-easy-handler to create a root page:

(define-easy-handler (index :uri "/") ()
  (with-html-output-to-string (_)
      (:html
       (:head
        (:title "Hello world")
       (:body
        (:h1 "Hello world!))))))

... and when I browse to http://localhost:4242/ I see that page.

But no static files are served from my www directory. E.g. if I create www/jquery-3.2.1.min.js and browse to http://localhost:4242/jquery-3.2.1.min.js I receive a 404.

127.0.0.1 - [2017-08-11 08:08:02] "GET /jquery-3.2.1.min.js HTTP/1.1" 404 355 "-" "Mozilla/5.0 (X11; FreeBSD amd64; rv:54.0) Gecko/20100101 Firefox/54.0"

HELLOWORLD> (directory (make-pathname :directory '(:relative "www") :name :wild :type "js"))
(#P"/usr/home/duncan/code/helloworld/www/jquery-3.2.1.min.js")

Solution

  • You must ensure that the directory and the files in it have proper permissions set. The directory needs to have the execute x permission to allow the server program to access the contents of the directory, and files need at least the read r permission.