通过特定路线包装文件
问题描述:
我为我的compojure应用程序设置了静态资源。我需要使用wrap-file
而不是wrap-resource
,因为我需要从文件系统提供静态文件。通过特定路线包装文件
我跟着这个wiki和配置wrap-file
现在我能够从http:\\localhost\static-file.css
我想要做的就是为我的静态资产在特定的情况下为我的静态资产http:\\localhost\context\static-file.css
答
有了Compojure路由,重要的是要记住,任何路由都可以封装在中间件中,而不仅仅是顶级集合的路由。考虑到这一点,我们可以使用Compojure的context
在需要的地方安装文件系统路由。
(defroutes app-routes
(GET "/" [] "Hello World")
(context "/context" []
(-> (route/not-found "File Not Found")
(wrap-file "path-to/static-files")))
(route/not-found "Not Found"))
(def app
(-> app-routes
(wrap-defaults site-defaults)))
太好了。谢谢。这工作 – prasann