问题描述
使用 ring(和 lein-ring 工具) - 我可以在开发中运行时根据文档提供来自资源"等的静态文件 - 但是 - 当我通过 lien uberwar 打包时,我不知道如何让它在容器中运行时提供这些文件.我在 wrap-resource 或设置 :resource-path 上看到了相互冲突的文档,但似乎都不起作用.
Using ring (and the lein-ring tools) - I am able to serve up static files from "resources" etc as per the docs when running in development - however - when I package things up via lien uberwar I have no idea how to make it serve those files when running in a container. I see conflicting docs on wrap-resource, or setting :resource-path but none seem to work.
推荐答案
根据 Compojure 的 Getting启动 Wiki,将 route/resources
放在您的路径下方:
As per Compojure's Getting Started Wiki, put route/resources
below your paths:
(defroutes main-routes
(GET "/" [] "<h1>Hello World Wide Web!</h1>")
(route/resources "/")
(route/not-found "Page not found"))
...然后,在您的项目中创建一个文件夹 resources/public
,将您的静态文件放在那里.在引用这些文件时,/resources/public
是隐式的,因此您可以编写如下内容:(include-css "/css/site.css")
.
...and then, create a folder resources/public
in your project, put your static files there. When referring to these files, the /resources/public
is implicit, so you can write something like: (include-css "/css/site.css")
.
这篇关于使用 ring/compojure 提供静态文件 - 来自战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!