-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rkt
37 lines (29 loc) · 1019 Bytes
/
app.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#lang racket
(provide (contract-out
[dispatch handler?]
[handle-error-not-found handler?]
[handle-error-crash (-> any/c exn? srv:response?)]))
(require (prefix-in srv: web-server/servlet)
(prefix-in http: web-server/http)
(prefix-in dis: web-server/dispatch))
(define handler?
(-> srv:request? srv:response?))
(define-values (dispatch _handler->url)
(dis:dispatch-rules
[("test") handle-test]))
;; TODO handle-subscribe-to-announce
(define/contract (handle-test req)
handler?
(http:response/output (λ (op) (displayln "works" op))))
(define/contract (handle-error-not-found req)
handler?
(srv:response/xexpr
'(html (head (title "error 404 : not found"))
(body "not found"))
#:code 404))
(define/contract (handle-error-crash url exn)
(-> any/c exn? srv:response?)
(srv:response/xexpr
'(html (head (title "error 500 : internal server error"))
(body "internal server error"))
#:code 500))