From ac21057c902cc762f35be039b89c88c6db2b1de1 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Mon, 3 Jan 2022 01:13:24 +0530 Subject: scripts: Make web server address and port configurable. * scripts/mumi.in (%options): Add address and port options. (show-mumi-usage): Mention address and port in mumi web usage. Pass on address and port options to start-mumi-web-server. --- scripts/mumi.in | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'scripts') diff --git a/scripts/mumi.in b/scripts/mumi.in index 5ec33cc..9c997a2 100644 --- a/scripts/mumi.in +++ b/scripts/mumi.in @@ -67,7 +67,23 @@ (define %options ;; Specifications of the command-line options - (list (option '("listen-repl") #f #t + (list (option '("address") #t #f + (lambda (opt name arg result) + (catch #t + (lambda () + (inet-pton AF_INET arg)) + (lambda _ + (error "invalid web server address" arg))) + (alist-cons 'address arg + (alist-delete 'address result)))) + (option '("port") #t #f + (lambda (opt name arg result) + (let ((port (string->number arg))) + (if port + (alist-cons 'port port + (alist-delete 'port result)) + (error "invalid web server port" arg))))) + (option '("listen-repl") #f #t (lambda (opt name arg result) (let ((port (cond (arg => string->number) (else %default-repl-server-port)))) @@ -104,7 +120,7 @@ (define (show-mumi-usage) (format (current-error-port) " - `mumi web [--listen-repl[=port]] [--disable-mailer]': + `mumi web [--address=address] [--port=port] [--listen-repl[=port]] [--disable-mailer]': start the application web server. `mumi mailer --sender=SENDER --smtp=SMTP: @@ -140,5 +156,8 @@ "REPL server listening on port ~a~%" repl-port) (spawn-server (make-tcp-server-socket #:port repl-port)))) - (start-mumi-web-server "0.0.0.0" 1234)))) + (start-mumi-web-server (or (assoc-ref opts 'address) + "0.0.0.0") + (or (assoc-ref opts 'port) + 1234))))) (_ (show-mumi-usage))) -- cgit v1.2.3