diff options
Diffstat (limited to 'prototypes/c3b2/web.scm')
-rwxr-xr-x | prototypes/c3b2/web.scm | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/prototypes/c3b2/web.scm b/prototypes/c3b2/web.scm new file mode 100755 index 0000000..aadd744 --- /dev/null +++ b/prototypes/c3b2/web.scm | |||
@@ -0,0 +1,64 @@ | |||
1 | #!/bin/sh | ||
2 | # -*- scheme -*- | ||
3 | exec guile -L $(pwd) -e '(@@ (web) main)' -s "$0" "$@" | ||
4 | !# | ||
5 | ;;; Copyright © 2014 David Thompson <davet@gnu.org> | ||
6 | ;;; Copyright © 2015-2017 Amirouche Boubekki <amirouche@hypermove.net> | ||
7 | ;; | ||
8 | ;; This program is free software: you can redistribute it and/or modify | ||
9 | ;; it under the terms of the GNU General Public License as published by | ||
10 | ;; the Free Software Foundation, either version 3 of the License, or | ||
11 | ;; (at your option) any later version. | ||
12 | |||
13 | ;; This program is distributed in the hope that it will be useful, | ||
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | ;; GNU General Public License for more details. | ||
17 | |||
18 | ;; You should have received a copy of the GNU General Public License | ||
19 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
20 | (define-module (web)) | ||
21 | |||
22 | ;; stdlib | ||
23 | (use-modules (ice-9 match)) | ||
24 | (use-modules (web request)) | ||
25 | (use-modules (web uri)) | ||
26 | |||
27 | ;; third party | ||
28 | (use-modules (fibers web server)) | ||
29 | |||
30 | ;; local | ||
31 | (use-modules (web decode)) | ||
32 | (use-modules (web helpers)) | ||
33 | (use-modules (web html)) | ||
34 | (use-modules (web mime-types)) | ||
35 | (use-modules (web static)) | ||
36 | |||
37 | |||
38 | (setlocale LC_ALL "") | ||
39 | |||
40 | ;;; | ||
41 | |||
42 | (define (template body-class body) | ||
43 | `((doctype "html") | ||
44 | (html | ||
45 | (head | ||
46 | (meta (@ (charset "utf-8"))) | ||
47 | (title "guile-web boilerplate") | ||
48 | (link (@ (rel "stylesheet") (href "/static/normalize.css"))) | ||
49 | (link (@ (rel "stylesheet") (href "/static/main.css")))) | ||
50 | (body | ||
51 | (div (h1 (a (@ (href "/")) "c3b2"))) | ||
52 | ,body)))) | ||
53 | |||
54 | |||
55 | (define (handler request body) | ||
56 | (match (cons (request-method request) (request-path-components request)) | ||
57 | (('GET) (render-html (template "index" '(div "Héllo Guilers")))) | ||
58 | (('GET "static" path ...) (render-static-asset path)) | ||
59 | (_ (not-found (uri->string (request-uri request)))))) | ||
60 | |||
61 | |||
62 | (define (main _) | ||
63 | (format #t "Server running @ http://localhost:8080\n") | ||
64 | (run-server handler)) | ||