public
Created — forked from jadudm/explore.rkt

Exploration of the PLT web server...

  • Download Gist
explore.rkt
Racket
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/base
 
;; Each library function is prefixed by the module it came from.
 
(require web-server/dispatch)
(define-values (dispatch blog-url)
(dispatch-rules
[("go") go]))
 
;; dispatch-rules patterns cover the entire URL, not just the prefix,
;; so your serve-static only matches "/" not anything with that as a
;; prefix. Also, (next-dispatcher) is the default 'else' rule, so it's
;; not necessary.
 
(require web-server/http)
(define (go req)
(response/xexpr
`(html (body (p "Dynamically")))))
 
;; No real comments here :P
 
(require racket/runtime-path)
(define-runtime-path here ".")
 
;; (current-directory) is the directory that you start the server
;; from, not the directory where the server's source file is
;; located. The best way to get that is with define-runtime-path
 
(require web-server/servlet-env)
(serve/servlet dispatch
#:extra-files-paths (list (build-path here "htdocs"))
#:servlet-path "/"
#:servlet-regexp #rx"")
 
;; #:launch-browser? #t is not necessary because its the default.
 
;; #:servlet-regexp #rx"" is the key because it means that the server
;; covers all URLs, not just the servlet's path.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.