source: project/demonstrations/spiffy/webserver.scm @ 20625

Last change on this file since 20625 was 20625, checked in by sjamaan, 10 years ago

Add basic Spiffy demo

File size: 1.4 KB
Line 
1(use spiffy simple-directory-handler
2     spiffy-uri-match intarweb uri-common sxml-transforms)
3
4(define (send-sxml-response sxml)
5  (with-headers `((connection close))
6    (lambda ()
7      (write-logged-response)))
8  (with-output-to-port (response-port (current-response))
9    (lambda ()
10      (SRV:send-reply (pre-post-order sxml universal-conversion-rules)))))
11
12(define my-custom-routes
13  `(((/ "greeting")
14     (GET ,(lambda _
15             (let* ((q (uri-query (request-uri (current-request))))
16                    (name (alist-ref 'name q))
17                    (greeting (if (and name (not (string=? name "")))
18                                  (sprintf "Hi there, ~A!" name)
19                                  "Please type in your name below")))
20               (send-sxml-response
21                `(html
22                  (head (title ,greeting))
23                  (body
24                   (h1 ,greeting)
25                   (form
26                    (input (@ (type "text") (name "name")))
27                    (input (@ (type "submit") (value "Go!"))))
28                   (p "If you're bored, you can "
29                      (a (@ (href "/"))
30                         "go back to browsing the docroot")))))))))))
31
32(vhost-map        ; Make route matching available on all virtual hosts
33 `((".*" . ,(uri-match/spiffy my-custom-routes))))
34
35;; Let simple-directory-handler handle directories (default is 304 access denied)
36(handle-directory simple-directory-handler)
37
38(start-server)
Note: See TracBrowser for help on using the repository browser.