make only some routes cached

This commit is contained in:
2025-06-29 04:10:23 -07:00
parent ff046a6b6b
commit 842719b102

View File

@ -83,18 +83,21 @@
#(param value))))))) #(param value)))))))
(defn shtml-file-response [file [code 200] [template-params {}]] (defn shtml-file-response [file [code 200] [template-params {}]]
(dict :code code :body (parse-html-file f"./www/site/html/{file}" #** template-params))) (dict
:code code
:headers {"Connection" "keep-alive" "Keep-Alive" "timeout=5 max=200"}
:body (parse-html-file f"./www/site/html/{file}" #** template-params)))
(defn raw-file-response [file [code 200]] (defn raw-file-response [file [code 200]]
(dict :code code #** (dict (zip ["headers" "body"] (send-raw-file f"./www/site/{file}"))))) (dict :code code #** (dict (zip ["headers" "body"] (send-raw-file f"./www/site/{file}")))))
(defn [(route "/" "GET")] /home #route-args (shtml-file-response "home.html")) (defn [(route "/" "GET")] /home #route-args (shtml-file-response "home.html"))
(defn [(route "/html/*" "GET") (if-file-exists :base-path "./www/site/html" :otherwise (error 404 "not found"))] /html/* #route-args (shtml-file-response path)) (defn [(route "/html/*" "GET") (if-file-exists :base-path "./www/site/html" :otherwise (error 404 "not found"))] /html/* #route-args (shtml-file-response path))
(defn [(route "/assets/*" "GET") (if-file-exists :base-path "./www/site/" :otherwise (error 404 "not found"))] /assets/* #route-args (raw-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 template-args))
(defn [(route "/comment" "POST")] /comments #route-args (create-comment request)) (defn [(route "/comment" "POST")] /comments #route-args (create-comment request))
(defn [(route "/robots.txt" "GET") ] /robots #route-args (dict :code 200 :headers {"Content-Type" "text/plain"} :body "User-agent *\nDisallow: /\n")) (defn [lru-cache (route "/robots.txt" "GET") ] /robots #route-args (dict :code 200 :headers {"Content-Type" "text/plain"} :body "User-agent *\nDisallow: /\n"))
(defn+ [lru-cache] match-request [{method "method" {path "path"} "route" :as request}] (defn+ match-request [{method "method" {path "path"} "route" :as request}]
((get (routes.get-route-by-path path) method) method path request)) ((get (routes.get-route-by-path path) method) method path request))