1.4 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.
| ||||||||||||||||||||||||||||
| → (-> void) | ||||||||||||||||||||||||||||
| dispatch : dispatcher/c | ||||||||||||||||||||||||||||
| tcp@ : (unit/c (import) (export tcp^)) = 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-server-config^, invokes the dispatch-server@, and calls its serve function.
The #:tcp@ keyword is provided for building an SSL server. See How do I set up the server to use HTTPS?.
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)) |
| ||||||||||||||||||||||||||||
| → (-> void) | ||||||||||||||||||||||||||||
| dispatch : dispatcher/c | ||||||||||||||||||||||||||||
| tcp@ : (unit/c (import) (export tcp^)) = 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.
| ||||||||||||||||||||||||
| → (-> void) | ||||||||||||||||||||||||
| dispatch : dispatcher/c | ||||||||||||||||||||||||
| tcp@ : (unit/c (import) (export tcp^)) = raw:tcp@ | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
| 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.
| (serve/web-config@ config@ [#:tcp@ tcp@]) → (-> void) |
| config@ : (unit/c (import) (export web-config^)) |
| tcp@ : (unit/c (import) (export tcp^)) = raw:tcp@ |
Starts the Web Server with the settings defined by the given web-config^ unit.
It is very useful to combine this with configuration-table->web-config@ and configuration-table-sexpr->web-config@:
| (serve/web-config@ |
| (configuration-table->web-config@ |
| default-configuration-table-path)) |
| (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.