使用 ring/compojure 提供静态文件 - 来自战争 [英] Serving static files with ring/compojure - from a war

查看:13
本文介绍了使用 ring/compojure 提供静态文件 - 来自战争的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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").

这是一个部署到 cloudbees 的示例.

这篇关于使用 ring/compojure 提供静态文件 - 来自战争的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆