44 lines
1.5 KiB
Scheme
44 lines
1.5 KiB
Scheme
;;; gembooru.scm ;;;
|
|
|
|
(use-modules (ice-9 match)
|
|
(web uri)
|
|
(config)
|
|
(connection)
|
|
(gemini)
|
|
(template)
|
|
(endpoint index)
|
|
(endpoint search)
|
|
(endpoint upload)
|
|
(endpoint post))
|
|
|
|
|
|
(define (handle-client client options i/o)
|
|
;; Handle incoming client connections by routing to the correct handler
|
|
;; functions based on scheme, host, and path
|
|
(let* ((headers (parse-request-headers i/o))
|
|
(uri (car headers))
|
|
(parameters (cdr headers))
|
|
(path (split-and-decode-uri-path (uri-path uri))))
|
|
;; TODO: Should probably log this in a dedicated access file
|
|
(format #t "~a: Requested ~a\n" (client->string client) (uri->string uri))
|
|
|
|
(match path
|
|
(("upload") (endpoint/upload i/o options uri parameters))
|
|
|
|
(("search") (endpoint/search i/o options uri))
|
|
|
|
(("post" "view" id) (endpoint/view-post i/o options id))
|
|
(("post" id) (endpoint/post i/o options uri id))
|
|
|
|
(() (endpoint/index i/o options uri))
|
|
(_ (endpoint/not-found i/o uri)))))
|
|
|
|
|
|
(let* ((options (build-options/command-line))
|
|
(templates (build-templates-from-files options))
|
|
(credentials (credentials-from-file (options-certificate options)
|
|
(options-private-key options))))
|
|
(set-options-templates! options templates)
|
|
|
|
(start-ssl-server credentials options handle-client
|
|
#:port (uri-port (options-host-uri options))))
|