From 05d707d80ac9298c004cffbba5a1867ebcfb4050 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Wed, 12 Apr 2017 11:23:41 -0700 Subject: [PATCH] add `--local` option to `raco start` (closes #143) --- pollen/private/command.rkt | 27 +++++++++++++++------------ pollen/private/project-server.rkt | 4 ++-- pollen/private/ts.rktd | 2 +- pollen/scribblings/raco.scrbl | 3 +++ pollen/setup.rkt | 2 +- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pollen/private/command.rkt b/pollen/private/command.rkt index c536a22..fcca04a 100644 --- a/pollen/private/command.rkt +++ b/pollen/private/command.rkt @@ -117,13 +117,15 @@ version print the version" (current-server-port) (make-publish-di (displayln (format "rendering ~a" (string-join (map ->string path-args) " "))) (apply render-batch path-args))))) + (define (handle-start) - (define launch-wanted (make-parameter #f)) + (define launch-wanted #f) + (define localhost-wanted #f) (define clargs (command-line #:program "raco pollen start" #:argv (vector-drop (current-command-line-arguments) 1) ; snip the 'start' from the front #:once-each - [("--launch" "-l") "Launch browser after start" - (launch-wanted #t)] + [("--launch" "-l") "Launch browser after start" (set! launch-wanted #t)] + [("--local") "Restrict access to localhost" (set! localhost-wanted #t)] #:args other-args other-args)) (define dir (path->directory-path (get-first-arg-or-current-dir clargs))) @@ -134,9 +136,10 @@ version print the version" (current-server-port) (make-publish-di (when (and port (not (exact-positive-integer? port))) (error (format "~a is not a valid port number" port))) (parameterize ([current-project-root dir] - [current-server-port (or port default-project-server-port)]) + [current-server-port (or port (setup:project-server-port))] + [current-server-listen-ip (and localhost-wanted "127.0.0.1")]) (displayln "Starting project server ...") - ((dynamic-require 'pollen/private/project-server 'start-server) (format "/~a" (setup:main-pagetree dir)) (launch-wanted)))) + ((dynamic-require 'pollen/private/project-server 'start-server) (format "/~a" (setup:main-pagetree dir)) launch-wanted))) (define (make-publish-dir-name [arg-command-name #f]) (let ([user-publish-path (expand-user-path (->path (setup:publish-directory)))]) @@ -152,13 +155,13 @@ version print the version" (current-server-port) (make-publish-di (vector-ref (current-command-line-arguments) 0)) (define force-target-overwrite? (make-parameter #t)) (define other-args (command-line - ;; drop command name - #:argv (vector-drop (current-command-line-arguments) 1) - #:once-each - [("-c" "--confirm") "Confirm overwrite of existing dest dir" - (force-target-overwrite? #f)] - #:args other-args - other-args)) + ;; drop command name + #:argv (vector-drop (current-command-line-arguments) 1) + #:once-each + [("-c" "--confirm") "Confirm overwrite of existing dest dir" + (force-target-overwrite? #f)] + #:args other-args + other-args)) ;; other-args looks like (list [maybe-source-dir-arg] [maybe-dest-dir-arg]) (define source-dir (simplify-path (get-first-arg-or-current-dir other-args))) diff --git a/pollen/private/project-server.rkt b/pollen/private/project-server.rkt index 31a39ed..8583b30 100755 --- a/pollen/private/project-server.rkt +++ b/pollen/private/project-server.rkt @@ -28,13 +28,13 @@ (message (format "Project server is ~a" server-name) "(Ctrl+C to exit)") (message (format "Project dashboard is ~a/~a" server-name (setup:main-pagetree))) (message "Ready to rock") - + (parameterize ([error-print-width 1000]) (serve/servlet pollen-servlet #:launch-browser? open-browser-window? #:servlet-path servlet-path #:port (current-server-port) - #:listen-ip #f + #:listen-ip (current-server-listen-ip) #:servlet-regexp #rx"" ; respond to top level #:command-line? #t #:file-not-found-responder route-404 diff --git a/pollen/private/ts.rktd b/pollen/private/ts.rktd index 2385d8f..1c244fa 100644 --- a/pollen/private/ts.rktd +++ b/pollen/private/ts.rktd @@ -1 +1 @@ -1491857384 +1492021421 diff --git a/pollen/scribblings/raco.scrbl b/pollen/scribblings/raco.scrbl index 96ff80e..c723f3b 100644 --- a/pollen/scribblings/raco.scrbl +++ b/pollen/scribblings/raco.scrbl @@ -69,6 +69,9 @@ If you want to start in the current directory but with a different port, use @li Adding the optional @exec{-l} or @exec{--launch} switch will open the main project dashboard in your web browser after the project server starts. +Adding the optional @exec{--local} switch will restrict the project server to responding to requests from localhost. (By default, the project server will respond to requests from any client.) + + @section{@exec{raco pollen render}} Render all preprocessor source files and then all pagetree files found in the current directory. If none of these files are found, a pagetree will be generated for the directory (which will include all source files) and then rendered. diff --git a/pollen/setup.rkt b/pollen/setup.rkt index 22ca6e2..1201ab1 100644 --- a/pollen/setup.rkt +++ b/pollen/setup.rkt @@ -92,10 +92,10 @@ (define-settable paths-excluded-from-dashboard (map string->path (list "poldash.css" "compiled"))) - (define-settable project-server-port 8080) (define+provide current-server-port (make-parameter (project-server-port))) +(define+provide current-server-listen-ip (make-parameter #f)) (define-settable dashboard-css "poldash.css")