Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (require web-server/servlet)
- (require web-server/servlet-env)
- (define (http-response content)
- (response/full
- 200 ; HTTP response code.
- #"OK" ; HTTP response message.
- (current-seconds) ; Timestamp.
- TEXT/HTML-MIME-TYPE ; MIME type for content.
- '() ; Additional HTTP headers.
- (list ; Content (in bytes) to send to the browser.
- (string->bytes/utf-8 content))))
- (define (show-time-page request)
- (http-response (number->string (current-seconds))))
- (define (greeting-page request)
- (http-response (list-ref '("Hi" "Hello") (random 2))))
- ;; URL routing table (URL dispatcher).
- (define-values (dispatch generate-url)
- (dispatch-rules
- [("time") show-time-page]
- [("hello") greeting-page] ; Notice this line.
- [else (error "There is no procedure to handle the url.")]))
- (define (request-handler request)
- (dispatch request))
- ;; Start the server.
- (serve/servlet
- request-handler
- #:launch-browser? #f
- #:quit? #f
- #:listen-ip "127.0.0.1"
- #:port 8001
- #:servlet-regexp #rx"")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement