Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Exploration of the PLT web server...
#lang racket/base
;; Each library function is prefixed by the module it came from.
(require web-server/dispatch)
(define-values (dispatch blog-url)
[("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)
`(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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.