summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix-web/controller.scm3
-rw-r--r--guix-web/render.scm19
-rw-r--r--guix-web/server.scm21
3 files changed, 21 insertions, 22 deletions
diff --git a/guix-web/controller.scm b/guix-web/controller.scm
index ad91008..61df575 100644
--- a/guix-web/controller.scm
+++ b/guix-web/controller.scm
@@ -49,4 +49,5 @@
(unprocessable-entity))))
((GET "librejs")
(render-html (librejs)))
- (_ #f)))
+ ((GET path ...)
+ (render-static-asset path))))
diff --git a/guix-web/render.scm b/guix-web/render.scm
index 835585f..ef0d93f 100644
--- a/guix-web/render.scm
+++ b/guix-web/render.scm
@@ -16,18 +16,35 @@
;;; <http://www.gnu.org/licenses/>.
(define-module (guix-web render)
+ #:use-module (ice-9 binary-ports)
#:use-module (web response)
#:use-module (web uri)
#:use-module (sxml simple)
#:use-module (json)
#:use-module (guix-web config)
- #:export (render-html
+ #:use-module (guix-web util)
+ #:export (render-static-asset
+ render-html
render-json
not-found
unprocessable-entity
created
redirect))
+(define file-mime-types
+ '(("css" . (text/css))
+ ("js" . (text/javascript))
+ ("png" . (image/png))))
+
+(define (render-static-asset path)
+ (let ((file-name (string-join (cons* guix-web-asset-dir path) "/")))
+ (if (and (file-exists? file-name)
+ (not (directory? file-name)))
+ (list `((content-type . ,(assoc-ref file-mime-types
+ (file-extension file-name))))
+ (call-with-input-file file-name get-bytevector-all))
+ (not-found (string->uri file-name)))))
+
(define (render-html sxml)
(list '((content-type . (text/html)))
(lambda (port)
diff --git a/guix-web/server.scm b/guix-web/server.scm
index 25f92f5..c713616 100644
--- a/guix-web/server.scm
+++ b/guix-web/server.scm
@@ -16,7 +16,6 @@
;;; <http://www.gnu.org/licenses/>.
(define-module (guix-web server)
- #:use-module (ice-9 binary-ports)
#:use-module (ice-9 match)
#:use-module (srfi srfi-1)
#:use-module (web http)
@@ -29,22 +28,6 @@
#:use-module (guix-web util)
#:export (start-guix-web))
-(define file-mime-types
- '(("css" . (text/css))
- ("js" . (text/javascript))
- ("png" . (image/png))))
-
-(define (serve-static-asset request)
- (let ((filename (string-join
- (cons guix-web-asset-dir
- (request-path-components request))
- "/")))
- (and (file-exists? filename)
- (not (directory? filename))
- (list `((content-type . ,(assoc-ref file-mime-types
- (file-extension filename))))
- (call-with-input-file filename get-bytevector-all)))))
-
(define (run-controller controller request)
(controller (cons (request-method request)
(request-path-components request))))
@@ -55,9 +38,7 @@
(uri-path (request-uri request)))
(apply values
(append
- (or (run-controller controller request)
- (serve-static-asset request)
- (not-found (request-uri request)))
+ (run-controller controller request)
(list controller))))
(define (start-guix-web controller)