http-server example: Resolve access to subfolder

This commit is contained in:
zhongxiao 2020-06-23 02:11:25 +08:00 committed by GitHub
parent 834c78c044
commit 5282755f8e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -34,7 +34,7 @@
(string/join (if attrs? (rest body) body))
(name tag))))
body (cond
(not (.exists f)) ""
(not (.exists f)) (str path " not exist")
(.isFile f) (slurp f)
(.isDirectory f) (format "<!DOCTYPE html>\n%s"
(html :html
@ -45,7 +45,10 @@
(html :tt
(apply html :pre
(for [i (.list f)]
(html :div (html :a {:href (format "\"%s\"" i)} i)))))))))]
(html :div
(html :a
{:href (str (if (> (count path) 1) path) "/" i)} i)
))))))))]
(prn path)
(.write out (format "HTTP/1.1 %s OK\r\nContent-Length: %s\r\n\r\n%s"
status