foxbox/foxbox.scm

37 lines
1.3 KiB
Scheme

;;; foxbox.scm
(use-modules (ice-9 getopt-long)
(web server)
(foxbox route)
(foxbox option)
(foxbox api index)
(foxbox api file))
(define (print-version) (format #t "FoxBox v0.0.1\n"))
(define (print-help) (format #t "USAGE: guile -L mod foxbox -c CONFIG\n"))
(define router
`((GET "^\\/$" . ,index)
(POST "^\\/$" . ,file/post)
#;(GET "^\\/[a-z0-9]{6}\\..+$" . ,download-file)
#;(PATCH "^\\/[a-z0-9]{6}\\..+$" . ,modify-file)
#;(DELETE "^\\/[a-z0-9]{6}\\..+$" . ,delete-file)))
(define option-specification
'((version (single-char #\v) (value #f))
(help (single-char #\h) (value #f))
(configuration (single-char #\c) (value #t))))
(let* ((options (getopt-long (command-line) option-specification))
(cfg (option-ref options 'configuration #f)))
(cond ((option-ref options 'help #f) (print-help))
((option-ref options 'version #f) (print-version))
(else (parameterize ((configuration-file (or cfg (configuration-file))))
(call-with-parameterized-configuration-file
(lambda ()
(run-server (make-router router not-found)
'http `(#:port ,(port)))))))))