【发布时间】:2016-09-25 11:28:37
【问题描述】:
我有一个位于resources/public/index.html 的index.html 并定义了以下路由(应用程序被拆分得更多,只是使代码简洁):
(ns example.example
(:require [compojure.route :as route]))
(defroutes routes
(GET "/" [] (resource-response "index.html" {:root "public"} "text/html")))
(defroutes application-routes
routes
(route/resources "/")
(route/not-found (resource-response "index.html" {:root "public"} "text/html")))
(def application
(wrap-defaults application-routes site-defaults))
但是,当我转到 localhost:8090/ 时,它会下载 html 文件而不是渲染它。
如果我转到localhost:8090/index.html,它会正确呈现文件,所以我认为我的路由不正确,但在查看示例后我不太清楚为什么。
【问题讨论】:
-
这个确切的问题已解决here。
-
@kongeor 使用
resp/redirect仍然会导致 html 文件被下载而不是呈现