aboutsummaryrefslogtreecommitdiff
path: root/web/webserver.scm
diff options
context:
space:
mode:
Diffstat (limited to 'web/webserver.scm')
-rwxr-xr-xweb/webserver.scm44
1 files changed, 44 insertions, 0 deletions
diff --git a/web/webserver.scm b/web/webserver.scm
index a60f477..91ff6d6 100755
--- a/web/webserver.scm
+++ b/web/webserver.scm
@@ -19,6 +19,7 @@
(srfi srfi-1)
(srfi srfi-11) ; let-values
(srfi srfi-26)
+ (rnrs io ports) ; bytevector-all
(web http)
(web client)
(web request)
@@ -31,6 +32,7 @@
(gn data species)
(gn data group)
(web sxml)
+ (web view view)
(web view doc))
@@ -71,12 +73,50 @@ otherwise search for set/group data"
(list (build-response #:code 404)
(string-append "Resource not found: " (uri->string uri))))
+
+(define file-mime-types
+ '(("css" . (text/css))
+ ("js" . (text/javascript))
+ ("svg" . (image/svg+xml))
+ ("png" . (image/png))
+ ("gif" . (image/gif))
+ ("jpg" . (image/jpg))
+ ("woff" . (application/font-woff))
+ ("ttf" . (application/octet-stream))
+ ("html" . (text/html))))
+
+(define (file-extension file-name)
+ (last (string-split file-name #\.)))
+
+(define* (render-static-image path #:key (extra-headers '()))
+ (list `((content-type
+ . ,(assoc-ref file-mime-types
+ (file-extension "CMOR.jpg"))) ; (last-modified . ,(time-utc->date modified))
+ )
+ (call-with-input-file "./static/images/CMOR.jpg" get-bytevector-all)))
+
+#!
+(call-with-input-file "./static/images/CMOR.jpg" get-bytevector-all)
+(list (append extra-headers
+ '((content-type . (application/octet-stream)))
+ (lambda (port)
+ (put-bytevector port
+ (call-with-input-file "./static/images/CMOR.jpg" get-bytevector-all)
+ )
+!#
+
(define* (render-doc path page #:optional rec #:key (extra-headers '()))
(list (append extra-headers
'((content-type . (text/html))))
(lambda (port)
(sxml->html (view-doc path page rec) port))))
+(define* (render-brand path #:optional rec #:key (extra-headers '()))
+ (list (append extra-headers
+ '((content-type . (text/html))))
+ (lambda (port)
+ (sxml->html (view-brand path) port))))
+
(define (render-json json)
(list '((content-type . (application/json)))
(lambda (port)
@@ -95,6 +135,10 @@ otherwise search for set/group data"
(render-json info))
(('GET "version")
(render-json get-version))
+ (('GET "static" "images" path)
+ (render-static-image path))
+ (('GET "brand" path)
+ (render-brand path))
(('GET "doc" "species.html")
(render-doc "doc" "species.html" (get-species-meta)))
(('GET "doc" taxon)