fix bugs in router
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
(import functools [lru-cache])
|
||||
(import os.path [isdir :as dir? isfile :as file? abspath])
|
||||
(import asyncio)
|
||||
(import urllib.parse [quote-plus])
|
||||
|
||||
(defn :async error [code message]
|
||||
(return (dict
|
||||
@ -95,7 +96,7 @@
|
||||
(defn 303-if-not-arpa [[unless (fn [#* _] False)]]
|
||||
(fn [f]
|
||||
(fn [method path request]
|
||||
(if (or (. request (get "headers") (get "Host") (endswith "arpa")) (unless request))
|
||||
(if (or (. request (get "headers") (get "Host") (endswith "arpa")) (unless request) True)
|
||||
(f method path request)
|
||||
(dict
|
||||
:code 303
|
||||
@ -116,7 +117,7 @@
|
||||
(defn [(route "/" "GET")] /home #route-args (shtml-file-response "home.html"))
|
||||
(defn [(route "/html/*" GET) (if-file-exists :base-path "./www/site/html" :otherwise (fn :async [#* _] #await (error 404 "not found")))] /html/* #route-args (shtml-file-response path))
|
||||
(defn [lru-cache (route "/assets/*" "GET") (if-file-exists :base-path "./www/site/" :otherwise (error 404 "not found"))] /assets/* #route-args (raw-file-response path))
|
||||
(defn [(route "/html/view-thought.html" "GET") (forward-params "thought" "filter-tag")] /html/view-thought #route-args [#** template-args] (shtml-file-response "/html/view-thought.html" :template-params template-args))
|
||||
(defn [(route "/html/view-thought.html" "GET") (forward-params "thought" "filter-tag")] /html/view-thought #route-args [#** template-args] (shtml-file-response "/html/view-thought.html" :template-params (dict (map (fn [arg] #((get arg 0) (. (get arg 1) (replace "'" "'")))) (. template-args (items))))))
|
||||
(defn [(route "/comment" "POST")] /comments #route-args (create-comment request))
|
||||
(defn [lru-cache (route "/robots.txt" "GET") ] /robots #route-args (dict :code 200 :headers {"Content-Type" "text/plain"} :body "User-agent *\nDisallow: /\n"))
|
||||
|
||||
@ -132,10 +133,10 @@
|
||||
:prev (+ "http://" (get (arpa-n-gon.prev-member members current) "arpa-domain"))
|
||||
:n_gon (arpa-n-gon.n-gon-name (len members)))))
|
||||
|
||||
(defn [(route "/arpa-n-gon/next" GET) (303-if-not-arpa) (forward-params "current" )(require-params "current")] /arpa-n-gon/next #route-args [current] (dict
|
||||
(defn :async [(route "/arpa-n-gon/next" GET) (303-if-not-arpa) (forward-params "current" )(require-params "current")] /arpa-n-gon/next #route-args [current] (dict
|
||||
:code 303
|
||||
:headers {"Location" (+ "http://" (get (arpa-n-gon.next-member members current) "arpa-domain"))}))
|
||||
|
||||
(defn [(route "/arpa-n-gon/prev" GET) (303-if-not-arpa) (forward-params "current") (require-params "current")] /arpa-n-gon/next #route-args [current] (dict
|
||||
(defn :async [(route "/arpa-n-gon/prev" GET) (303-if-not-arpa) (forward-params "current") (require-params "current")] /arpa-n-gon/next #route-args [current] (dict
|
||||
:code 303
|
||||
:headers {"Location" (+ "http://" (get (arpa-n-gon.prev-member members current) "arpa-domain"))}))
|
||||
|
Reference in New Issue
Block a user