[plt-scheme] servlet-dispatcher and static files.

From: vannadiz (vika.lapsar at gmail.com)
Date: Tue Jan 26 17:23:24 EST 2010

Hello,
I need to write servlet using  *.css files.
Without dispatchers i have done this in such way.
  (serve/servlet start
                 #:extra-files-paths
                   (list (build-path my-path "htdocs"))

But when I'm trying this with dispatchers, it doesn't work(css file
not found) becouse of using #:servlet-regexp  #rx""

  (serve/servlet start
                 #:extra-files-paths
                   (list (build-path my-path "htdocs")
                  #:servlet-regexp  #rx"")

Should I rewrite regexp to stop getting static files into dispatcher
or maybe there is some better way?

Sample code with static files and servlet-dispatcher below.

#lang scheme
 (require web-server/servlet-env
          web-server/servlet
          web-server/managers/manager)

   (define (start-helloworld request)
   '(html
     (link ((rel "stylesheet")
         (href "/gallery.css")
         (type "text/css")))
     (body (div
            ((id "wrap"))  "HelloWorld"))))

  (define (start-error request)
   '(html
     (link ((rel "stylesheet")
         (href "/gallery.css")
         (type "text/css")))
     (body (div
            ((id "wrap")) "Error"))))

  (define-values (servlet-dispatcher generator)
      (dispatch-rules
       [("") start-helloworld]
       [else start-error]))

(define (start req)
  (servlet-dispatcher req))

  (serve/servlet start
                 #:launch-browser? #t
                 #:extra-files-paths
                 (list (build-path my-path "htdocs"))
                 #:servlet-path "/"
                 #:servlet-regexp  #rx"" )


Posted on the users mailing list.