diff --git a/collects/web-server/scribblings/servlet-env.scrbl b/collects/web-server/scribblings/servlet-env.scrbl index 7df1062fda..2d1b30787b 100644 --- a/collects/web-server/scribblings/servlet-env.scrbl +++ b/collects/web-server/scribblings/servlet-env.scrbl @@ -9,6 +9,43 @@ The @web-server provides a way to quickly configure and start a server instance. +Here's a simple example: +@schememod[ +scheme +(require web-server/servlet + web-server/servlet-env) + +(define (my-app request) + `(html (head (title "Hello world!")) + (body (p "Hey out there!")))) + +(serve/servlet my-app) +] + +Suppose you'd like to change the port to something else, change the last line to: +@schemeblock[ +(serve/servlet my-app + #:port 8080) +] + +By default the URL for your servlet is @filepath{http://localhost:8000/servlets/standalone.ss}, +suppose you wanted it to be @filepath{http://localhost:8000/hello.ss}: +@schemeblock[ +(serve/servlet my-app + #:servlet-path (build-path "hello.ss")) +] +For the time being, this path must end in @filepath{.ss} or @filepath{.scm}. + +Suppose you wanted to use a style-sheet (@filepath{style.css}) found on your Desktop (@filepath{/Users/jay/Desktop/}): +@schemeblock[ +(serve/servlet my-app + #:extra-files-paths + (list + (build-path "/Users/jay/Desktop"))) +] +These files are served @emph{in addition} to those from the @scheme[#:server-root-path] @filepath{htdocs} directory. +Notice that you may pass any number of extra paths. + @defproc[(serve/servlet [servlet (request? . -> . response?)] [#:launch-browser? launch-browser? boolean? #t] [#:quit? quit? boolean? #t] @@ -17,7 +54,7 @@ The @web-server provides a way to quickly configure and start a server instance. [#:manager manager manager? default-threshold-LRU-manager] [#:servlet-namespace servlet-namespace (listof module-path?) empty] [#:server-root-path server-root-path path? default-server-root-path] - [#:extra-files-path extra-files-path path? (build-path server-root-path "htdocs")] + [#:extra-files-paths extra-files-paths (listof path?) (list (build-path server-root-path "htdocs"))] [#:servlets-root servlets-root path? (build-path server-root-path ".")] [#:file-not-found-path file-not-found-path path? (build-path server-root-path "conf" "not-found.html")] @@ -43,8 +80,8 @@ The @web-server provides a way to quickly configure and start a server instance. The modules specified by @scheme[servlet-namespace] are shared with other servlets. The server files are rooted at @scheme[server-root-path] (which is defaultly the distribution root.) - A file path, in addition to the @filepath["htdocs"] directory under @scheme[server-root-path] may be - provided with @scheme[extra-files-path]. These files are checked first. + File paths, in addition to the @filepath["htdocs"] directory under @scheme[server-root-path] may be + provided with @scheme[extra-files-paths]. These paths are checked first, in the order they appear in the list. The @filepath["servlets"] directory is expected at @scheme[servlets-root]. If a file cannot be found, @scheme[file-not-found-path] is used as an error response. diff --git a/collects/web-server/servlet-env.ss b/collects/web-server/servlet-env.ss index 297e3cc2c7..a3d77ad6b8 100644 --- a/collects/web-server/servlet-env.ss +++ b/collects/web-server/servlet-env.ss @@ -42,17 +42,17 @@ (provide/contract [serve/servlet (((request? . -> . response?)) (#:launch-browser? boolean? - #:quit? boolean? - #:listen-ip string? - #:port number? - #:manager manager? - #:servlet-namespace (listof module-path?) - #:server-root-path path? - #:extra-files-path path? - #:servlets-root path? - #:file-not-found-path path? - #:mime-types-path path? - #:servlet-path path?) + #:quit? boolean? + #:listen-ip string? + #:port number? + #:manager manager? + #:servlet-namespace (listof module-path?) + #:server-root-path path? + #:extra-files-paths (listof path?) + #:servlets-root path? + #:file-not-found-path path? + #:mime-types-path path? + #:servlet-path path?) . ->* . void)]) (define (serve/servlet new-servlet @@ -78,8 +78,9 @@ [servlet-namespace empty] #:server-root-path [server-root-path (directory-part default-configuration-table-path)] - #:extra-files-path - [extra-files-path (build-path server-root-path "htdocs")] + #:extra-files-paths + [extra-files-paths (list (build-path server-root-path "htdocs"))] + ; XXX Add support for other servlets #:servlets-root [servlets-root (build-path server-root-path ".")] #:file-not-found-path @@ -112,11 +113,14 @@ (values (build-path servlets-root servlet-path) empty)))]) servlet-dispatch)) - (files:make - #:url->path (fsmap:make-url->path - extra-files-path) - #:path->mime-type (make-path->mime-type mime-types-path) - #:indices (list "index.html" "index.htm")) + (apply sequencer:make + (map (lambda (extra-files-path) + (files:make + #:url->path (fsmap:make-url->path + extra-files-path) + #:path->mime-type (make-path->mime-type mime-types-path) + #:indices (list "index.html" "index.htm"))) + extra-files-paths)) (files:make #:url->path (fsmap:make-url->path (build-path server-root-path "htdocs"))