1 Running the Web Server
2 Scheme Servlets
3 Web Language Servlets
4 Configuration
5 Dispatchers
6 Web Config Unit
7 Web Server Unit
8 Continuation Managers
9 Internal
10 Troubleshooting
11 Acknowledgements
Index
On this page:
serve
serve/ ports
serve/ ips+ ports
do-not-return
Version: 4.0.2

 

1.2 Functional

 (require web-server/web-server)

"web-server.ss" provides a number of functions for easing embedding of the Web Server in other applications, or loading a custom dispatcher. See "run.ss" for an example of such a script.

(serve

 

 

 

#:dispatch dispatch

 

 

 [

#:tcp@ tcp@

 

 

 

#:port port

 

 

 

#:listen-ip listen-ip

 

 

 

#:max-waiting max-waiting

 

 

 

#:initial-connection-timeout initial-connection-timeout])

 

  (-> void)

  dispatch : dispatcher?

  tcp@ : tcp-unit^ = raw:tcp@

  port : integer? = 80

  listen-ip : (or/c string? false/c) = #f

  max-waiting : integer? = 40

  initial-connection-timeout : integer? = 60

Constructs an appropriate dispatch-config^, invokes the dispatch-server@, and calls its serve function.

Here’s an example of a simple web server that serves files from a given path:

  (define (start-file-server base)

    (serve

     #:dispatch

     (files:make

      #:url->path (make-url->path base)

      #:path->mime-type

      (lambda (path)

        #"application/octet-stream"))

     #:port 8080))

(serve/ports

 

 

 

#:dispatch dispatch

 

 

 [

#:tcp@ tcp@

 

 

 

#:ports ports

 

 

 

#:listen-ip listen-ip

 

 

 

#:max-waiting max-waiting

 

 

 

#:initial-connection-timeout initial-connection-timeout])

 

  (-> void)

  dispatch : dispatcher?

  tcp@ : tcp-unit^ = raw:tcp@

  ports : (listof integer?) = (list 80)

  listen-ip : (or/c string? false/c) = #f

  max-waiting : integer? = 40

  initial-connection-timeout : integer? = 60

Calls serve multiple times, once for each port, and returns a function that shuts down all of the server instances.

(serve/ips+ports

 

 

 

#:dispatch dispatch

 

 

 [

#:tcp@ tcp@

 

 

 

#:ips+ports ips+ports

 

 

 

#:max-waiting max-waiting

 

 

 

#:initial-connection-timeout initial-connection-timeout])

 

  (-> void)

  dispatch : dispatcher?

  tcp@ : tcp-unit^ = raw:tcp@

  

ips+ports

 

:

 

(listof (cons/c (or/c string? false/c) (listof integer?)))

 

 

 

=

 

(list (cons #f (list 80)))

  max-waiting : integer? = 40

  initial-connection-timeout : integer? = 60

Calls serve/ports multiple times, once for each ip, and returns a function that shuts down all of the server instances.

(do-not-return)  void

This function does not return. If you are writing a script to load the Web Server you are likely to want to call this functions at the end of your script.