routing bug relating to sending a 404 when no such route

This commit is contained in:
2025-07-17 02:28:32 -07:00
parent 529675b325
commit 96e73c072b

View File

@ -76,7 +76,7 @@
(fn [method path request]
(if (file? f"{base-path}{path}")
(f method path request)
otherwise))))
(otherwise method path request)))))
(defn forward-params [#* params]
(fn [f]
@ -110,35 +110,32 @@
(defn :async raw-file-response [file [code 200]]
(dict :code code #** (dict (zip ["headers" "body"] #await (send-raw-file f"./www/site/{file}")))))
(defn+ match-request [{method "method" {path "path"} "route" :as request}]
;; (try
((get (routes.get-route-by-path path) method) method path request))
;; (except [Exception]
;; (return (error 500 "server error")))))
(defn+ :async match-request [{method "method" {path "path"} "route" :as request}]
#await ((get (routes.get-route-by-path path) method) method path request))
(defn :async [(route "/" "GET")] /home #route-args #await (shtml-file-response "home.html"))
(defn :async [(route "/html/*" "GET") (if-file-exists :base-path "./www/site/html" :otherwise (error 404 "not found"))] /html/* #route-args #await (shtml-file-response path))
(defn :async [lru-cache (route "/assets/*" "GET") (if-file-exists :base-path "./www/site/" :otherwise (error 404 "not found"))] /assets/* #route-args #await (raw-file-response path))
(defn :async [(route "/html/view-thought.html" "GET") (forward-params "thought" "filter-tag")] /html/view-thought #route-args [#** template-args] #await (shtml-file-response "/html/view-thought.html" :template-params template-args))
(defn :async [(route "/comment" "POST")] /comments #route-args (create-comment request))
(defn :async [lru-cache (route "/robots.txt" "GET") ] /robots #route-args (dict :code 200 :headers {"Content-Type" "text/plain"} :body "User-agent *\nDisallow: /\n"))
(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 "/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"))
;; *.arpa web n-gon
(setv members (arpa-n-gon.get-members))
(defn :async [(route "/arpa-n-gon" GET) (303-if-not-arpa)] /arpa-n-gon #route-args #await (shtml-file-response "arpa-n-gon.html" :template-params (dict :n_gon (arpa-n-gon.n-gon-name (len members)) :n_gon_inc (arpa-n-gon.n-gon-name (+ (len members) 1)) :n (len members))))
(defn [(route "/arpa-n-gon" GET) (303-if-not-arpa)] /arpa-n-gon #route-args (shtml-file-response "arpa-n-gon.html" :template-params (dict :n_gon (arpa-n-gon.n-gon-name (len members)) :n_gon_inc (arpa-n-gon.n-gon-name (+ (len members) 1)) :n (len members))))
(defn :async [(route "/arpa-n-gon/nav" GET) (303-if-not-arpa :unless (fn [request] (in "from-iframe" (. request (get "route") (get "parameters") (keys))))) (forward-params "current" "style") (require-params "current") ] /arpa-n-gon/nav #route-args [current [style None]]
#await (shtml-file-response "arpa-n-gon-nav.html" :no-exec True :template-params (dict
(defn [(route "/arpa-n-gon/nav" GET) (303-if-not-arpa :unless (fn [request] (in "from-iframe" (. request (get "route") (get "parameters") (keys))))) (forward-params "current" "style") (require-params "current") ] /arpa-n-gon/nav #route-args [current [style None]]
(shtml-file-response "arpa-n-gon-nav.html" :no-exec True :template-params (dict
:style style
:next (+ "http://" (get (arpa-n-gon.next-member members current) "arpa-domain"))
:prev (+ "http://" (get (arpa-n-gon.prev-member members current) "arpa-domain"))
:n_gon (arpa-n-gon.n-gon-name (len members)))))
(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
(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
:code 303
:headers {"Location" (+ "http://" (get (arpa-n-gon.next-member members current) "arpa-domain"))}))
(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
(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
:code 303
:headers {"Location" (+ "http://" (get (arpa-n-gon.prev-member members current) "arpa-domain"))}))