about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@gmail.com>2017-12-31T14·03+0100
committerVincent Ambo <tazjin@gmail.com>2017-12-31T14·31+0100
commitbd3b2782b938a29d6952d7a06c040e59571d825e (patch)
tree04881f585bd90dcb12998e9672f08b0842544caa
parent8703b6102c348d5e860af83a980ba5e1585e3964 (diff)
feat(lisp): Correctly set location for static assets in Nix builds
In order to let Hunchentoot serve the static assets from the correct
location, the *static-file-location* parameter is set before image
dumping based on the $out-envvar which is present during the build
process.

This can easily be set manually in the config file if required by a
user.
-rw-r--r--build.lisp6
-rw-r--r--src/gemma.lisp15
2 files changed, 12 insertions, 9 deletions
diff --git a/build.lisp b/build.lisp
index 3c8ce3372177..ce67a91f6585 100644
--- a/build.lisp
+++ b/build.lisp
@@ -28,10 +28,4 @@
 ;; cl-prevalence is not in the current Quicklisp -> Nix snapshot
 (ql:quickload "cl-prevalence")
 
-;; the $out path should be set in the application to let Hunchentoot serve the
-;; correct static files.
-
-(if (sb-posix:getenv "out")
-    (defvar *gemma-nix-out-dir* (sb-posix:getenv "out")))
-
 (asdf:operate 'asdf:program-op :gemma)
diff --git a/src/gemma.lisp b/src/gemma.lisp
index 526eb0453549..b8a20addd907 100644
--- a/src/gemma.lisp
+++ b/src/gemma.lisp
@@ -29,6 +29,14 @@
 (defvar *gemma-port* 4242
   "Port on which the Gemma web server listens.")
 
+(defvar *static-file-location*
+  (or (in-case-of (sb-posix:getenv "out")
+        (concatenate 'string it "/share/gemma/"))
+      "frontend/")
+  "Folder from which to serve static assets. If built inside of Nix,
+  the folder is concatenated with the output path at which the files
+  are expected to be.")
+
 (defun initialise-persistence (data-dir)
   (defvar *p-tasks*
     (cl-prevalence:make-prevalence-system data-dir)
@@ -129,9 +137,10 @@ maximum interval."
                       "/etc/gemma/config.lisp")))
 
   ;; Set up web server
-  (hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port *gemma-port*))
-
-  ;; ... and register all handlers.
+  (hunchentoot:start
+   (make-instance 'hunchentoot:easy-acceptor
+                  :port *gemma-port*
+                  :document-root *static-file-location*))
 
   ;; Task listing handler
   (hunchentoot:define-easy-handler