about summary refs log tree commit diff
path: root/bin/gn-guile-webserver
blob: 36a924d5a42ee2e983c21952cff8aa57c9180747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/@GUILE@ --no-auto-compile
!#

;;; gn-guile-webserver --- the stripped branding webserver for
;;; aging.genenetwork.org.
;;; Copyright © 2026 Pjotr Prins <pjotr.prins@thebird.nl>
;;;
;;; Runs the (web webserver-aging) module.  Used by the gn-guile
;;; container (gn-machines/genenetwork/containers/
;;; gn-guile-container.scm); the package build substitutes @GUILE@
;;; with the store guile and wraps the script with its load paths.

(use-modules (ice-9 match))

(define (parse-port args)
  (let loop ((args args))
    (match args
      (("--port" p . rest) p)
      (((? string->number p) . rest) p)
      ((_ . rest) (loop rest))
      (() "8091"))))

(define (main args)
  ;; TLS: the views fetch their markdown from raw.githubusercontent.com;
  ;; point guile/gnutls at the CA bundle (the package build wraps the
  ;; script with SSL_CERT_FILE from the system profile, but be safe if
  ;; run from a bare environment).
  (unless (getenv "SSL_CERT_FILE")
    (setenv "SSL_CERT_FILE"
            "/run/current-system/profile/etc/ssl/certs/ca-certificates.crt"))
  (unless (getenv "GUILE_TLS_CERTIFICATE_DIRECTORY")
    (setenv "GUILE_TLS_CERTIFICATE_DIRECTORY"
            "/run/current-system/profile/etc/ssl/certs"))
  (let ((port (parse-port args)))
    (let ((webserver (resolve-module '(web webserver-aging) #t)))
      ((module-ref webserver 'start-web-server)
       "0.0.0.0" (string->number port)))))

(main (command-line))