start command: fix default value for port (#244)

* start command: fix default value for port

Defaulting the port to "8080" at the `command-line' level breaks
customization via `pollen.rkt'.

* test-project-port: connect to server to verify that it's up
pull/245/head
Bogdan Popa 4 years ago committed by GitHub
parent 62b19a07d8
commit 6cd57203c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -182,13 +182,13 @@ version print the version" (current-server-port) (make-publish-di
#:once-each #:once-each
[("--launch" "-l") "Launch browser after start" (set! launch-wanted #t)] [("--launch" "-l") "Launch browser after start" (set! launch-wanted #t)]
[("--local") "Restrict access to localhost" (set! localhost-wanted #t)] [("--local") "Restrict access to localhost" (set! localhost-wanted #t)]
#:args ([dir (current-directory)] [port "8080"]) #:args ([dir (current-directory)] [port #f])
(define parsed-dir (define parsed-dir
(path->directory-path (normalize-path (very-nice-path dir)))) (path->directory-path (normalize-path (very-nice-path dir))))
(unless (directory-exists? parsed-dir) (unless (directory-exists? parsed-dir)
(error (format "~a is not a directory" parsed-dir))) (error (format "~a is not a directory" parsed-dir)))
(define parsed-port (string->number port)) (define parsed-port (and port (string->number port)))
(when (and parsed-port (not (exact-positive-integer? parsed-port))) (when (and parsed-port (not (exact-positive-integer? parsed-port)))
(error (format "~a is not a valid port number" parsed-port))) (error (format "~a is not a valid port number" parsed-port)))
(values parsed-dir parsed-port))) (values parsed-dir parsed-port)))

@ -0,0 +1,6 @@
#lang racket/base
(module setup racket/base
(provide (all-defined-out))
(define project-server-port
9876))

@ -0,0 +1,51 @@
#lang racket/base
(require racket/port
racket/runtime-path
racket/tcp
rackunit)
(define-runtime-path project-port-dir "data/project-port")
(define the-port
(dynamic-require
`(submod ,(build-path project-port-dir "pollen.rkt") setup)
'project-server-port))
(define-values (in out)
(make-pipe))
(define thd
(parameterize ([current-output-port out]
[current-error-port out]
[current-directory project-port-dir]
[current-command-line-arguments (vector "start")]
[exit-handler (lambda (code)
(fail (format "abnormal exit from raco command~n code: ~a" code))
(kill-thread thd))])
(thread
(lambda ()
(dynamic-require '(submod pollen/private/command raco) #f)))))
(dynamic-wind
void
(lambda ()
(sync
(handle-evt
(regexp-match-evt #rx"ready to rock" in)
void)
(handle-evt
(alarm-evt (+ (current-inexact-milliseconds) 5000))
(lambda (_)
(fail "timed out while waiting for server to start"))))
(with-handlers ([exn:fail?
(lambda (e)
(fail (format "failed to connect to server: ~a" (exn-message e))))])
(define-values (cin cout)
(tcp-connect "127.0.0.1" the-port))
(close-output-port cout)
(close-input-port cin)))
(lambda ()
(break-thread thd)
(thread-wait thd)))
Loading…
Cancel
Save