generated from dannypsnl-fork/racket-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.rkt
38 lines (31 loc) · 918 Bytes
/
server.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
38
#lang racket
(provide server-port
jsonrpc-start)
(require web-server/servlet-env
web-server/http/request-structs
web-server/http/json
json)
(define server-port (make-parameter 4389))
(define (jsonrpc-start jsonrpc-handler)
(λ (request)
(define json-str (request-post-data/raw request))
(match json-str
[#f
(response/jsexpr
(hasheq 'jsonrpc "2.0"
'id "0"
'result '()))]
[json-str
(define json (bytes->jsexpr json-str))
(jsonrpc-handler (hash-ref json 'id)
(hash-ref json 'method)
(hash-ref json 'params))])))
(module+ main
(require "response.rkt")
(define (user-handler id method params)
(success-response params))
(serve/servlet
(jsonrpc-start user-handler)
#:port (server-port)
#:launch-browser? #f
#:servlet-path "/"))