从 uberjar 运行时,Ring 的文件响应对我不起作用。我都试过了
(response/file-response "index.html" {:root "resources/public"})
和
(response/response (clojure.java.io/as-file (clojure.java.io/resource "public/index.html")))
如何在 uberjar 中的“/”处提供 index.html?
最佳答案
您需要使用 ring.util.response/resource-response
来提供在类路径中找到的文件。假设您想要提供在 überjar 的 resources
目录中找到的 index.html
文件,参数几乎与您调用 file-response 时完全一样
:
(response/resource-response "index.html" {:root "public"})
它是 "public"
而不是 "resources/public"
,因为 resources
是包含在überjar,所以 public
将在顶层的类路径中找到。 (如果从文件系统而不是 überjar 运行,这也是正确的;然后路径需要相对于类路径上的某个顶级目录。)
关于web-applications - 使用来自 uberjar 的文件响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18875117/