server: Remove unnecessary indirection.
[software/mumi.git] / mumi / web / server.scm
1 ;;; mumi -- Mediocre, uh, mail interface
2 ;;; Copyright © 2017, 2020 Ricardo Wurmus <rekado@elephly.net>
3 ;;;
4 ;;; This program is free software: you can redistribute it and/or
5 ;;; modify it under the terms of the GNU Affero General Public License
6 ;;; as published by the Free Software Foundation, either version 3 of
7 ;;; the License, or (at your option) any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ;;; Affero General Public License for more details.
13 ;;;
14 ;;; You should have received a copy of the GNU Affero General Public
15 ;;; License along with this program. If not, see
16 ;;; <http://www.gnu.org/licenses/>.
17
18 (define-module (mumi web server)
19 #:use-module (srfi srfi-1)
20 #:use-module (web http)
21 #:use-module (web request)
22 #:use-module (web uri)
23 #:use-module (web server)
24 #:use-module (mumi web controller)
25 #:use-module (mumi web util)
26 #:export (start-mumi-web-server))
27
28 (define (handler request body)
29 (format #t "~a ~a\n"
30 (request-method request)
31 (uri-path (request-uri request)))
32 (apply values
33 ((controller request body)
34 (cons (request-method request)
35 (request-path-components request)))))
36
37 (define (start-mumi-web-server port)
38 (run-server handler
39 'http
40 (list
41 #:addr INADDR_ANY
42 #:port port)))