summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorArun Isaac2022-06-29 00:18:18 +0530
committerArun Isaac2022-06-29 00:18:18 +0530
commita8023a99111233fec4b6050c6de3130097e84483 (patch)
tree0614a2f25b75b69ddd0a928b4bd4f63ad265514e /bin
parent58dcd6b052a61229e0ceb021076a1f450a80aea9 (diff)
downloadtissue-a8023a99111233fec4b6050c6de3130097e84483.tar.gz
tissue-a8023a99111233fec4b6050c6de3130097e84483.tar.lz
tissue-a8023a99111233fec4b6050c6de3130097e84483.zip
web: server: Add web server for search.
* tissue/web/server.scm: New file.
* tissue/document.scm (document-sxml-snippet): New public function.
(document->sxml): New generic method.
* tissue/issue.scm: Import (web uri).
(document->sxml): New generic method.
* bin/tissue: Import (system repl server) and (tissue web server).
(address->socket-address, tissue-run-web): New function.
(print-usage): List `tissue run-web' subcommand.
(main): Call tissue-run-web.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/tissue70
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/tissue b/bin/tissue
index e29cf3c..d7d4424 100755
--- a/bin/tissue
+++ b/bin/tissue
@@ -32,6 +32,7 @@ exec guile --no-auto-compile -s "$0" "$@"
         (ice-9 match)
         (ice-9 popen)
         (ice-9 regex)
+        (system repl server)
         (term ansi-color)
         (git)
         (xapian wrap)
@@ -43,6 +44,7 @@ exec guile --no-auto-compile -s "$0" "$@"
         (tissue search)
         (tissue tissue)
         (tissue utils)
+        (tissue web server)
         (tissue web static))
 
 (define %state-directory
@@ -190,6 +192,72 @@ Export the repository as a website to OUTPUT-DIRECTORY.
                       (tissue-configuration-web-css (load-config))
                       (tissue-configuration-web-files (load-config)))))))
 
+(define (address->socket-address address port)
+  "Convert ADDRESS and PORT to a socket address."
+  (cond
+   ;; IPv4
+   ((string-contains address ".")
+    (make-socket-address AF_INET
+                         (inet-pton AF_INET address)
+                         port))
+   ;; IPv6
+   ((string-contains address ":")
+    (make-socket-address AF_INET6
+                         (inet-pton AF_INET6 address)
+                         port))
+   ;; Unix socket
+   (else
+    (make-socket-address AF_UNIX address))))
+
+(define tissue-run-web
+  (match-lambda*
+    (("--help")
+     (format #t "Usage: ~a run-web
+Run a web search service for the current repository.
+
+  --address=IP       run web server listening on IP address [default=127.0.0.1]
+  --port=PORT        run web server listening on PORT [default=8080]
+  --listen-repl=P    run REPL server listening on port or path P
+"
+             (command-line-program)))
+    (args
+     (let ((args (args-fold args
+                            (list (option (list "address")
+                                          #t #f
+                                          (lambda (opt name arg result)
+                                            (acons 'address arg result)))
+                                  (option (list "port")
+                                          #t #f
+                                          (lambda (opt name arg result)
+                                            (acons 'port (string->number arg)
+                                                   result)))
+                                  (option '("listen-repl")
+                                          #t #f
+                                          (lambda (opt name arg result)
+                                            (acons 'listen-repl arg result))))
+                            invalid-option
+                            invalid-operand
+                            ;; Default address and port
+                            '((address . "127.0.0.1")
+                              (port . 8080)))))
+       (let ((listen-repl (assq-ref args 'listen-repl)))
+         (when listen-repl
+           (spawn-server (cond
+                          ((string? listen-repl)
+                           (format (current-error-port)
+                                   "REPL server listening on port ~a~%"
+                                   listen-repl)
+                           (make-unix-domain-server-socket #:path listen-repl))
+                          (else
+                           (format (current-error-port)
+                                   "REPL server listening on ~a~%"
+                                   listen-repl)
+                           (make-unix-domain-server-socket #:path listen-repl))))))
+       (start-web-server (address->socket-address (assq-ref args 'address)
+                                                  (assq-ref args 'port))
+                         %xapian-index
+                         (tissue-configuration-web-css (load-config)))))))
+
 (define (print-usage)
   (format #t "Usage: ~a COMMAND [OPTIONS] [ARGS]
 
@@ -199,6 +267,7 @@ COMMAND must be one of the sub-commands listed below:
   show      show the text of an issue
   repl      run a Guile script in a tissue environment
   web       export repository as website
+  run-web   run a web search service
 
 To get usage information for one of these sub-commands, run
   ~a COMMAND --help
@@ -266,6 +335,7 @@ top-level of the git repository."
                       ("show" tissue-show)
                       ("repl" tissue-repl)
                       ("web" tissue-web)
+                      ("run-web" tissue-run-web)
                       (invalid-command
                        (format (current-error-port) "Invalid command `~a'~%~%"
                                invalid-command)