|
|
|
@ -1,7 +1,15 @@
|
|
|
|
|
#lang web-server/base
|
|
|
|
|
#lang racket/base
|
|
|
|
|
(require racket/runtime-path
|
|
|
|
|
web-server/servlet-env
|
|
|
|
|
web-server/dispatch
|
|
|
|
|
web-server/web-server
|
|
|
|
|
web-server/servlet-dispatch
|
|
|
|
|
web-server/private/mime-types
|
|
|
|
|
(prefix-in files: web-server/dispatchers/dispatch-files)
|
|
|
|
|
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
|
|
|
|
web-server/dispatchers/filesystem-map
|
|
|
|
|
net/url
|
|
|
|
|
net/sendurl
|
|
|
|
|
"project-server-routes.rkt"
|
|
|
|
|
"log.rkt"
|
|
|
|
|
"../setup.rkt"
|
|
|
|
@ -12,20 +20,28 @@
|
|
|
|
|
|
|
|
|
|
(define-runtime-path mime-types "server-extras/mime.types")
|
|
|
|
|
|
|
|
|
|
(define (start-server servlet-path [open-browser-window? #f]
|
|
|
|
|
#:serve-only [serve-only? #false])
|
|
|
|
|
(define-values (pollen-servlet _)
|
|
|
|
|
(dispatch-rules
|
|
|
|
|
[((string-arg) ... (? (λ (x) (string=? "" x)))) route-index] ; last element of a "/"-terminated url is ""
|
|
|
|
|
[((string-arg) ... (? pagetree-source?)) route-dashboard]
|
|
|
|
|
[((string-arg) ... "in" (string-arg) ...) route-in]
|
|
|
|
|
[((string-arg) ... "out" (string-arg) ...) route-out]
|
|
|
|
|
[else route-default]))
|
|
|
|
|
(define (make-static-dispatcher-sequence . pths)
|
|
|
|
|
(apply sequencer:make
|
|
|
|
|
(for/list ([pth (in-list pths)])
|
|
|
|
|
(files:make
|
|
|
|
|
#:path->mime-type (make-path->mime-type mime-types)
|
|
|
|
|
#:url->path (make-url->path (path->string pth))))))
|
|
|
|
|
|
|
|
|
|
(define-values (pollen-servlet _)
|
|
|
|
|
(dispatch-rules
|
|
|
|
|
;; last element of a "/"-terminated url is ""
|
|
|
|
|
[((string-arg) ... "") route-index]
|
|
|
|
|
[((string-arg) ... (? pagetree-source?)) route-dashboard]
|
|
|
|
|
[((string-arg) ... "in" (string-arg) ...) route-in]
|
|
|
|
|
[((string-arg) ... "out" (string-arg) ...) route-out]
|
|
|
|
|
[else route-default]))
|
|
|
|
|
|
|
|
|
|
(define (start-server servlet-path [open-browser-window? #false] #:return [return? #false])
|
|
|
|
|
|
|
|
|
|
(define server-name (format "http://localhost:~a" (current-server-port)))
|
|
|
|
|
|
|
|
|
|
(message (format "welcome to Pollen ~a (Racket ~a)" pollen:version (version)))
|
|
|
|
|
(message (format "project root is ~a" (current-project-root)))
|
|
|
|
|
|
|
|
|
|
(define server-name (format "http://localhost:~a" (current-server-port)))
|
|
|
|
|
(message (format "project server is ~a (Ctrl+C to exit)" server-name))
|
|
|
|
|
(message (format "project dashboard is ~a/~a" server-name (setup:main-pagetree)))
|
|
|
|
|
(message (if (current-server-listen-ip)
|
|
|
|
@ -35,24 +51,21 @@
|
|
|
|
|
[else (current-server-listen-ip)]))
|
|
|
|
|
"project server permitting access to all clients"))
|
|
|
|
|
(message "ready to rock")
|
|
|
|
|
|
|
|
|
|
(cond
|
|
|
|
|
[serve-only?
|
|
|
|
|
(define stopper
|
|
|
|
|
((dynamic-require 'web-server/web-server 'serve)
|
|
|
|
|
#:dispatch ((dynamic-require 'web-server/servlet-dispatch 'dispatch/servlet) pollen-servlet)
|
|
|
|
|
#:listen-ip (current-server-listen-ip)
|
|
|
|
|
#:port (current-server-port)))
|
|
|
|
|
stopper]
|
|
|
|
|
[else
|
|
|
|
|
(parameterize ([error-print-width 1000])
|
|
|
|
|
(serve/servlet pollen-servlet
|
|
|
|
|
#:launch-browser? open-browser-window?
|
|
|
|
|
#:servlet-path servlet-path
|
|
|
|
|
#:port (current-server-port)
|
|
|
|
|
#:listen-ip (current-server-listen-ip)
|
|
|
|
|
#:servlet-regexp #rx"" ; respond to top level
|
|
|
|
|
#:command-line? #true
|
|
|
|
|
#:file-not-found-responder route-404
|
|
|
|
|
#:mime-types-path mime-types
|
|
|
|
|
#:extra-files-paths (list (current-server-extras-path) (current-project-root))))]))
|
|
|
|
|
|
|
|
|
|
(define stop-func
|
|
|
|
|
(parameterize ([error-print-width 1000])
|
|
|
|
|
(serve
|
|
|
|
|
#:dispatch (sequencer:make
|
|
|
|
|
(dispatch/servlet pollen-servlet)
|
|
|
|
|
(make-static-dispatcher-sequence
|
|
|
|
|
(current-project-root)
|
|
|
|
|
(current-server-extras-path))
|
|
|
|
|
(dispatch/servlet route-404))
|
|
|
|
|
#:listen-ip (current-server-listen-ip)
|
|
|
|
|
#:port (current-server-port))))
|
|
|
|
|
(when open-browser-window?
|
|
|
|
|
(send-url (string-append server-name servlet-path)))
|
|
|
|
|
(if return?
|
|
|
|
|
stop-func
|
|
|
|
|
(with-handlers ([exn:break? (λ (e) (stop-func) (message "project server stopped"))])
|
|
|
|
|
(do-not-return))))
|