minimal node-like spiffy added by caolanm on Fri Mar 9 16:23:10 2018

(use spiffy intarweb)

(define msg "hello\n")

;; this function is like a Connect middleware from nodejs,
;; call (continue) to pass control back to spiffy
(define (handler continue)
  ;; instead of being passed request and response as arguments
  ;; spiffy uses (current-request) and (current-response)
  (let ((res (update-response
              code: 200
              headers: (headers `((content-length ,(string-length msg)))))))
    ;; write the response head - like response.writeHead() in nodejs
    (write-response res)
    ;; write the response body - like response.write() in nodejs
    (display msg (response-port (current-response)))
    ;; complete the response - like response.end() in nodejs
    (finish-response-body res)))

;; this allows you to host multiple sites at different subdomains etc.
;; like nginx or similar - to use it like node, just set up a wildcard
  `((".*" . ,handler)))

;; like Server.listen() in nodejs