Changeset 33263 in project


Ignore:
Timestamp:
03/08/16 21:32:54 (5 years ago)
Author:
sjamaan
Message:

Summary: Add a dynamic example to spiffy docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/spiffy

    r33190 r33263  
    679679
    680680If you put this in {{/usr/local/libexec/spiffy.scm}} you can use [[/spiffy-init-script|this example init.d script]] or [[/spiffy-systemd-scripts|these example systemd scripts]] as-is, to launch Spiffy.
     681
     682==== A simple dynamic web page example
     683
     684If you would like to dynamically serve content, you can use a custom
     685handler in the vhost-map for the host on which you want to serve
     686this content:
     687
     688<enscript highlight="scheme">
     689(use spiffy intarweb uri-common)
     690
     691(define (handle-greeting continue)
     692  (let* ((uri (request-uri (current-request))))
     693    (if (equal? (uri-path uri) '(/ "greeting"))
     694        (send-response status: 'ok body: "<h1>Hello!</h1>")
     695        (continue))))
     696
     697(vhost-map `(("localhost" . ,handle-greeting)))
     698
     699(start-server)
     700</enscript>
     701
     702It's not advised to use string concatenation for building HTML, as it
     703is rather unsafe and easy to get wrong.  For a slightly larger
     704example, see
     705[[http://bugs.call-cc.org/browser/project/demonstrations/spiffy|this
     706demonstration of Spiffy with SXML]].
     707
    681708
    682709==== Network tweaks
Note: See TracChangeset for help on using the changeset viewer.