[racket] Servlet static file paths, I just don't get it

From: Erich Rast (erich at snafu.de)
Date: Sat Sep 28 18:05:10 EDT 2013

This is driving me nuts, I just cannot find the place where my servlet
gets static files from. I run the following "server.scm" in a directory
in which there is also "htdocs/images/Sloth.png" but no matter what
combination of img src file paths and extra-file-paths I try,
respond-unknown does not want to display the Sloth.png when I click run:

#lang racket
(require web-server/web-server
(require "lottery/darkstar-lottery.scm")

(define (respond-unknown req)
  (response/xexpr '(html
     (head (title "The 3-Toed Sloth"))
      (img ([src "images/Sloth.png"]))
      (h1 "Under construction")))))

(define-values (dispatch input-url)
   (("lottery") lottery-app)
   (else respond-unknown)))

(serve/servlet dispatch ; answers requests
               #:servlet-path "" ; is the default URL
               #:extra-files-paths (list (build-path
               (current-directory) "htdocs")) 
               #:port 8080 ; is the port
               #:servlet-regexp #rx"")

How do I make the servlet serve the file "htdocs/images/Sloth.png"
relative to the servlet source directory and how do I address it in the
"img" tag? I tried absolute paths, too, but no luck.



P.S. For completeness, the content of

#lang racket
(require web-server/servlet
(provide lottery-app)

(define (draw n total)
    (shuffle (for/list ((i (in-range total)))
               (add1 i)))

(define (stringify numbers)
   (apply string-append
          (for/list ([n (in-list (reverse (cdr (reverse numbers))))])
            (format "~a, " n)))
   (format "~a" (car (reverse numbers)))))
(define (euromillions)
  (define (draw-5-of-50)
    (draw 5 50))
  (define (draw-2-of-11)
    (draw 2 11))
  (format "The next lottery result is ~a with additional numbers ~a."
          (stringify (draw-5-of-50))
          (stringify (draw-2-of-11))))
(define (lottery-app req)
   `(html (head (title "Euromillions"))
          (body (p ,(euromillions))))))
;(serve/servlet lottery-app
;               #:servlet-path "/lottery"
;               #:port 8080
;               #:command-line #t)

Posted on the users mailing list.