Commit ecb3b9ff authored by amirouche's avatar amirouche

web: rename 'handler' to 'router', and prefix handlers with 'route/'

parent c68d10e6
......@@ -17,7 +17,6 @@ send patches to amirouche+dev@hypermove.net.
* ROADMAP
** 0.0 blog engine
*** easy: rename "handler" to "router" and add a "route/" prefix to all routes
*** easy: in procedure names replace /template with /sxml
*** easy: add navigation form on every page
*** easy: Add transactions to all queries
......
......@@ -198,7 +198,7 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
(("/signin") (redirect "/signin"))
(("/signup") (redirect "/signup")))))
(define (index app request)
(define (route/index app request)
(let ((query (assoc-ref (request-query request) "query"))
(user (request-user request app)))
(call-with-values (lambda () (query->maybe-response query user))
......@@ -274,7 +274,7 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
(ref errors "password"))
,(form/submit "submit"))))
(define (signin/get request)
(define (route/signin/get request)
(sxml->response (signin/template '() '())))
(define (required value)
......@@ -307,7 +307,7 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
;; nowhere else, in particular it MUST NOT appear in urls.
(string-sign (grf3:vertex-uid user) (app-pepper app)))
(define (signin/post app request body)
(define (route/signin/post app request body)
(let ((form (decode body)))
(let ((errors (signin/form-validate form)))
(if (null? errors)
......@@ -347,7 +347,7 @@ exec guile -L $(pwd) -e '(@ (web) main)' -s "$0" "$@"
,(form/submit "submit"))))
(define (signup/get request)
(define (route/signup/get request)
(sxml->response (signup/template '() '())))
(define (username-valid? username)
......@@ -437,7 +437,7 @@ user vertex"
(app-init user))
user)))
(define (signup/post app request body)
(define (route/signup/post app request body)
(let ((form (decode body)))
(let ((errors (signup/form-validate form)))
(if (null? errors)
......@@ -448,7 +448,7 @@ user vertex"
(redirect "/signin"))
(sxml->response (signup/template form errors))))))
(define (handler app request body)
(define (router app request body)
(log-debug "~a ~a" (request-method request) (uri-path (request-uri request)))
(with-context*
;; TODO: only do it in debug mode
......@@ -456,11 +456,11 @@ user vertex"
(lambda (user)
(log-debug "user is ~s" (grf3:vertex-ref user 'user/username))))
(match (cons (request-method request) (request-path-components request))
('(GET) (index app request))
('(GET "signin") (signin/get request))
('(POST "signin") (signin/post app request body))
('(GET "signup") (signup/get request))
('(POST "signup") (signup/post app request body))
('(GET) (route/index app request))
('(GET "signin") (route/signin/get request))
('(POST "signin") (route/signin/post app request body))
('(GET "signup") (route/signup/get request))
('(POST "signup") (route/signup/post app request body))
(('GET "static" path ...) (render-static-asset path))
(_ (not-found (uri-path (request-uri request)))))))
......@@ -468,4 +468,4 @@ user vertex"
(format #t "Server running @ http://localhost:8080\n")
(let ((app (make-app "super-secret-string"))) ;; TODO: make it a fluid
(with-env (env-open* "wt" (list *feature-space*) "create,log=(enabled=true)")
(run-server (lambda (request body) (handler app request body))))))
(run-server (lambda (request body) (router app request body))))))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment