about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-04 10:30:20 +0000
committerPjotr <wrk@bosa.lan>2026-10-04 10:30:20 +0000
commitf2d53ea6fb3a273f3169c4ff62d5b1cec2fa5d20 (patch)
tree1233027618cba1b84d3b8373ada1732c10751f80
parent0e8e605434b37251e6729121c77afa963cebef6a (diff)
downloadgn-guile-f2d53ea6fb3a273f3169c4ff62d5b1cec2fa5d20.tar.gz
Add the stripped branding webserver for aging.genenetwork.org
web/webserver-aging.scm serves only the brand pages (home/aging/...),
css, static images and doc rendering -- the REST API (web/webserver.scm)
stays untouched for the full deployment.  bin/gn-guile-webserver is the
matching entry-point script (a plain guile script with an @GUILE@
shebang that package builds substitute, wrapped with their load paths).

Both are used by the gn-guile system container
(gn-machines/genenetwork/containers/gn-guile-container.scm), which
strips everything but the webserver from the package at build time:
the container serves ONLY aging.genenetwork.org and every REST/API
route is disabled.

Also compute the copyright year at run time: (current-year) in
(web sxml) returns (date-year (current-date)) and the aging/msk
footers render "Copyright © 2005-<current-year>" instead of the
stale hard-coded 2025.
-rwxr-xr-xbin/gn-guile-webserver39
-rw-r--r--web/sxml.scm8
-rw-r--r--web/view/brand/aging.scm2
-rw-r--r--web/view/brand/msk.scm2
-rw-r--r--web/webserver-aging.scm105
5 files changed, 153 insertions, 3 deletions
diff --git a/bin/gn-guile-webserver b/bin/gn-guile-webserver
new file mode 100755
index 0000000..36a924d
--- /dev/null
+++ b/bin/gn-guile-webserver
@@ -0,0 +1,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))
diff --git a/web/sxml.scm b/web/sxml.scm
index 29eeee3..aed93a3 100644
--- a/web/sxml.scm
+++ b/web/sxml.scm
@@ -23,11 +23,17 @@
 
 (define-module (web sxml)
   #:use-module (sxml simple)
+  #:use-module (srfi srfi-19)
   #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
   #:use-module (ice-9 format)
   #:use-module (ice-9 hash-table)
-  #:export (sxml->html))
+  #:export (sxml->html
+            current-year))
+
+(define (current-year)
+  "The current year, for copyright notices."
+  (date-year (current-date)))
 
 (define %self-closing-tags
   '(area base
diff --git a/web/view/brand/aging.scm b/web/view/brand/aging.scm
index f1c48c9..b520b8e 100644
--- a/web/view/brand/aging.scm
+++ b/web/view/brand/aging.scm
@@ -52,7 +52,7 @@
         ,info)
       (footer
        (hr)
-       (p "Copyright © 2005-2025 "
+       (p (string-append "Copyright © 2005-" (number->string (current-year)) " ")
           (a (@ (href "https://genenetwork.org/")) "GeneNetwork Webservices") " | GeneNetwork and this website runs fully on free software. See status and download the "
           (a (@ (href "https://ci.genenetwork.org/"))
              "source code") ".")))
diff --git a/web/view/brand/msk.scm b/web/view/brand/msk.scm
index 4cbcec4..6556cd1 100644
--- a/web/view/brand/msk.scm
+++ b/web/view/brand/msk.scm
@@ -51,7 +51,7 @@
         (p ,info)
         (footer
        (hr)
-       (p "Copyright © 2005-2025 "
+       (p (string-append "Copyright © 2005-" (number->string (current-year)) " ")
           (a (@ (href "https://genenetwork.org/")) "GeneNetwork Webservices") " | GeneNetwork and this website runs fully on free software. See status and download the "
           (a (@ (href "https://ci.genenetwork.org/"))
              "source code") ".")))
diff --git a/web/webserver-aging.scm b/web/webserver-aging.scm
new file mode 100644
index 0000000..e485309
--- /dev/null
+++ b/web/webserver-aging.scm
@@ -0,0 +1,105 @@
+;;; webserver-aging --- the branding webserver that serves
+;;; aging.genenetwork.org.
+;;; Copyright © 2026 Pjotr Prins <pjotr.prins@thebird.nl>
+;;;
+;;; This replaces the full REST API webserver (web/webserver.scm):
+;;; only the branding pages, css, static images and doc rendering
+;;; remain.  Used by the gn-guile container
+;;; (gn-machines/genenetwork/containers/gn-guile-container.scm), which
+;;; physically strips the REST API from the package.
+
+(define-module (web webserver-aging)
+  #:use-module (web server)
+  #:use-module (web request)
+  #:use-module (web response)
+  #:use-module (web uri)
+  ;; the (web sxml) serializer shipped with gn-guile -- it knows the
+  ;; views' doctype/raw extensions (guile core's (sxml simple) only
+  ;; has sxml->xml and guile-lib's (htmlprag) would render
+  ;; (doctype "html") as a literal <doctype> element)
+  #:use-module (web sxml)
+  #:use-module (rnrs io ports)
+  #:use-module (srfi srfi-1)
+  #:use-module (ice-9 match)
+  #:use-module (ice-9 format)
+  #:use-module (ice-9 receive)
+  #:use-module (web view view)
+  #:export (start-web-server))
+
+(define file-mime-types
+  '(("css" text/css)
+    ("js" text/javascript)
+    ("svg" image/svg+xml)
+    ("png" image/png)
+    ("gif" image/gif)
+    ("jpg" image/jpg)
+    ("jpeg" image/jpeg)
+    ("woff" application/font-woff)
+    ("ttf" application/octet-stream)
+    ("html" text/html)))
+
+(define (file-extension file-name)
+  (last (string-split file-name #\.)))
+
+(define (web-dir)
+  "The installed web/ directory of this package (css, static, doc)."
+  (dirname (dirname (search-path %load-path "web/view/view.scm"))))
+
+(define* (render-static-file path)
+  (let ((stat (stat path #f)))
+    (if stat
+        (list `((content-type . ,(assoc-ref file-mime-types
+                                            (file-extension path))))
+              (call-with-input-file path get-bytevector-all))
+        (not-found path))))
+
+(define (render-brand-page path)
+  (list '((content-type text/html))
+        (lambda (port)
+          (sxml->html (view-brand path) port))))
+
+(define (not-found path)
+  ;; routes return (list response body) -- the handler applies values
+  (list (build-response #:code 404)
+        (string-append "Not found: " path "
+")))
+
+(define (controller request body)
+  (match-lambda
+    ;; the aging.genenetwork.org front page
+    (('GET) (render-brand-page "aging"))
+    (('GET "home") (render-brand-page "aging"))
+    (('GET "home" "aging") (render-brand-page "aging"))
+    (('GET "home" "aging" path ...) (render-brand-page
+                                     (string-append "aging/"
+                                                    (string-join path "/"))))
+    (('GET "home" path ...) (render-brand-page (string-join path "/")))
+    (('GET "css" fn)
+     (render-static-file (string-append (web-dir) "/css/" fn)))
+    (('GET "static" "images" fn)
+     (render-static-file (string-append (web-dir) "/static/images/" fn)))
+    (('GET "static" fn ...)
+     (render-static-file (string-append (web-dir) "/static/"
+                                        (string-join fn "/"))))
+    (('GET "doc" path ...) (render-brand-page "aging"))
+    (_ (not-found (string-join (cons "/" (request-path-components request))
+                               "/")))))
+
+(define (request-path-components request)
+  (split-and-decode-uri-path (uri-path (request-uri request))))
+
+(define (handler request body)
+  (format #t "~a ~a
+" (request-method request)
+          (uri-path (request-uri request)))
+  (apply values ((controller request body)
+                 (cons (request-method request)
+                       (request-path-components request)))))
+
+(define (start-web-server address port)
+  (format (current-error-port)
+          "GN aging branding webserver listening on http://~a:~a/~%"
+          address port)
+  (run-server handler 'http
+              (list #:addr (inet-pton AF_INET address)
+                    #:port port)))