You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pollen/server.rkt

53 lines
2.1 KiB
Racket

#lang web-server
11 years ago
(require "startup.rkt")
(require web-server/servlet-env)
(require web-server/dispatch web-server/dispatchers/dispatch)
(require xml)
11 years ago
(require "server-routes.rkt" "debug.rkt" "readability.rkt" "world.rkt")
11 years ago
(define port-number 8088)
11 years ago
11 years ago
(message (format "Project root is ~a" PROJECT_ROOT))
11 years ago
(message (format "Project server is http://localhost:~a" port-number) "(Ctrl-C to exit)")
(define (logger req)
(define client (request-client-ip req))
11 years ago
(define url-string (url->string (request-uri req)))
(message "Request:" (string-replace url-string DASHBOARD_NAME " dashboard")
"from" (if (equal? client "::1") "localhost" client)))
(define/contract (route-wrapper route-proc)
(procedure? . -> . procedure?)
11 years ago
(λ(req . string-args)
(logger req)
(define path (apply build-path PROJECT_ROOT (flatten string-args)))
(response/xexpr (route-proc path))))
(define-values (start url)
(dispatch-rules
11 years ago
;; the match patterns for each rule represent /each/slashed/piece of a url
;; (as if the url is split on slashes into a list before matching)
;; dashboard page: works on any url of form /dir/dir/dir/poldash.html
;; todo: figure out how to use world:DASHBOARD_NAME here
11 years ago
[((string-arg) ... "poldash.html") (route-wrapper route-dashboard)]
11 years ago
;; raw viewer: works on any url of form /dir/dir/raw/name.html
;; (pattern matcher automatically takes out the "raw")
11 years ago
[((string-arg) ... "raw" (string-arg)) (route-wrapper route-raw)]
[((string-arg) ... "xexpr" (string-arg)) (route-wrapper route-xexpr)]
;; [((string-arg) ... "force" (string-arg)) (route-wrapper route-force)]
[else (λ(req)
;; because it's the "else" route, can't use string-arg matcher
(logger req)
(route-default req)
(next-dispatcher))]))
11 years ago
(message (format "Project dashboard is http://localhost:~a/pollen.html" port-number))
11 years ago
(message "Ready to rock")
11 years ago
(serve/servlet start
11 years ago
#:port port-number
#:listen-ip #f
#:servlet-regexp #rx"" ; respond to top level
#:command-line? #t
11 years ago
#:extra-files-paths (list (build-path PROJECT_ROOT)))