aboutsummaryrefslogtreecommitdiff
path: root/module/entry-points
diff options
context:
space:
mode:
Diffstat (limited to 'module/entry-points')
-rw-r--r--module/entry-points/server.scm34
1 files changed, 18 insertions, 16 deletions
diff --git a/module/entry-points/server.scm b/module/entry-points/server.scm
index 3dab6e9c..63fb83a8 100644
--- a/module/entry-points/server.scm
+++ b/module/entry-points/server.scm
@@ -39,20 +39,22 @@
(with-output-to-string
(lambda () (display "<!doctype html>\n") (sxml->xml sxml))))
+(define (// . args) (string-join args file-name-separator-string ))
+
(define (directory-table dir)
`(table
(thead
(tr (th "") (th "Name") (th "Perm")))
(tbody
,@(map (lambda (k)
- (let* ((stat (lstat k)))
+ (let* ((stat (lstat (// dir k))))
`(tr (td ,(case (stat:type stat)
[(directory) "📁"]
[(regular) "📰"]
[else "🙃"]))
- (td (a (@ (href "/" ,dir ,k)) ,k))
+ (td (a (@ (href "/" ,dir "/" ,k)) ,k))
(td ,(number->string (stat:perms stat) 8)))))
- (cddr (scandir dir))))))
+ (cdr (scandir dir))))))
(define-method (make-make-routes)
@@ -99,7 +101,7 @@
(ical-main (parse-iso-date start)
(parse-iso-date end))))))
- ;; TODO this returns "invalid" events, since the surrounding VCALENDAR is missing.
+ ;; TODO this fails if there's a period in the uid.
(GET "/calendar/:uid.ics" (uid)
(aif (get-event-by-uid uid)
(return '((content-type text/calendar))
@@ -109,23 +111,23 @@
(return (build-response code: 404)
(format #f "No component with UID=~a found." uid))))
- (GET "/static" ()
- (return
- '((content-type text/html))
- (sxml->html-string
- (directory-table "static/"))))
+ ;; NOTE this only handles files with extensions. Limited, but since this
+ ;; is mostly for development, and something like nginx should be used in
+ ;; production it isn't a huge problem.
- (GET "/static/:filename.css" (filename)
+ (GET "/static/:*{.*}.:ext" (* ext)
(return
- `((content-type text/css))
- (call-with-input-file (string-append "static/" filename ".css")
+ ;; TODO actually check mimetype
+ `((content-type ,(string->symbol (string-append "text/" ext))))
+ (call-with-input-file (string-append "static/" * "." ext)
read-string)))
- (GET "/static/:filename.js" (filename)
+ (GET "/static/:*{.*}" (*)
(return
- `((content-type text/javascript))
- (call-with-input-file (string-append "static/" filename ".js")
- read-string)))
+ '((content-type text/html))
+ (sxml->html-string
+ (directory-table (// "static" *)))))
+
(GET "/count" ()
;; (sleep 1)