On this page:
serve/ servlet
Version: 4.1.2

1.2 Simple Single Servlet Servers

 (require web-server/servlet-env)

The Web Server provides a way to quickly configure and start a server instance.

(serve/servlet servlet 
  [#:launch-browser? launch-browser? 
  #:quit? quit? 
  #:listen-ip listen-ip 
  #:port port 
  #:manager manager 
  #:servlet-namespace servlet-namespace 
  #:server-root-path server-root-path 
  #:extra-files-path extra-files-path 
  #:servlets-root servlets-root 
  #:file-not-found-path file-not-found-path 
  #:mime-types-path mime-types-path 
  #:servlet-path servlet-path]) 
  void
  servlet : (request? . -> . response?)
  launch-browser? : boolean? = #t
  quit? : boolean? = #t
  listen-ip : string? = "127.0.0.1"
  port : number? = 8000
  manager : manager? = default-threshold-LRU-manager
  servlet-namespace : (listof module-path?) = empty
  server-root-path : path? = default-server-root-path
  extra-files-path : path?
   = (build-path server-root-path "htdocs")
  servlets-root : path? = (build-path server-root-path ".")
  file-not-found-path : path?
   = (build-path server-root-path "conf" "not-found.html")
  mime-types-path : path?
   = (build-path server-root-path "mime.types")
  servlet-path : path? = "servlets/standalone.ss"

This sets up and starts a fairly default server instance.

servlet is installed as a server at servlet-path with manager as its continuation manager. (The default manager limits the amount of memory to 64 MB and deals with memory pressure as discussed in the make-threshold-LRU-manager documentation.)

If launch-browser? is true, then a web browser is opened to the servlet’s start page.

If quit? is true, then the URL "/quit" ends the server.

Advanced users may need the following options:

The server listens on listen-ip and port port.

The modules specified by servlet-namespace are shared with other servlets.

The server files are rooted at server-root-path (which is defaultly the distribution root.) A file path, in addition to the "htdocs" directory under server-root-path may be provided with extra-files-path. These files are checked first. The "servlets" directory is expected at servlets-root.

If a file cannot be found, file-not-found-path is used as an error response.

MIME types are looked up at mime-types-path.