[racket] Servlet static file paths, I just don't get it
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
web-server/dispatch
web-server/servlet-env
web-server/servlet)
(require "lottery/darkstar-lottery.scm")
(define (respond-unknown req)
(response/xexpr '(html
(head (title "The 3-Toed Sloth"))
(body
(img ([src "images/Sloth.png"]))
(h1 "Under construction")))))
(define-values (dispatch input-url)
(dispatch-rules
(("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.
Best,
Erich
P.S. For completeness, the content of
lottery/darkstar-lottery.scm:
#lang racket
(require web-server/servlet
web-server/servlet-env)
(provide lottery-app)
(define (draw n total)
(sort
(take
(shuffle (for/list ((i (in-range total)))
(add1 i)))
n)
<))
(define (stringify numbers)
(string-append
(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)
(response/xexpr
`(html (head (title "Euromillions"))
(body (p ,(euromillions))))))
;(serve/servlet lottery-app
; #:servlet-path "/lottery"
; #:port 8080
; #:command-line #t)