new-web.scm 956 B

123456789101112131415161718192021222324252627282930313233
  1. (use-modules (web server))
  2. (use-modules (web request)
  3. (web response)
  4. (web uri)
  5. (sxml simple))
  6. (define (request-path-components request)
  7. (split-and-decode-uri-path (uri-path (request-uri request))))
  8. (define (not-found request)
  9. (values (build-response #:code 404)
  10. (string-append "Resource not found: "
  11. (uri->string (request-uri request)))))
  12. (define (templatize title body)
  13. `(html (head (title ,title))
  14. (body ,@body)))
  15. (define (hello-hacker-handler request body)
  16. (if (equal? (request-path-components request)
  17. '("hacker"))
  18. (values
  19. (build-response #:headers '((content-type text/html)))
  20. (lambda (port)
  21. (let ([port 8080])
  22. (if sxml
  23. (begin
  24. (if doctype (display doctype port))
  25. (sxml->xml sxml port))))))
  26. (not-found request)))
  27. (run-server hello-hacker-handler)