15

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.

Michael Neale
  • 19,248
  • 19
  • 77
  • 109
  • For Google App Engine I could just but the static files directly in the `war/` directory. Template files (I use soy) actually stay in the `resource/` directory and somehow get compiled into the war directory. I suppose this is not possible / doesn't work in your case? – Paul Oct 19 '11 at 08:04

2 Answers2

24

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"))

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

Here is an example that deploys to cloudbees.

Dave Liepmann
  • 1,555
  • 1
  • 18
  • 22
Michael Neale
  • 19,248
  • 19
  • 77
  • 109
20

compojure.route/resources should do what you want.

Just put the files in resources/public and then add a route (resources "/") near the end of your routes list.

You need a fairly recent lein-ring for this to work correctly; older versions of lein-ring don't support the resources directory for public assets.

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
Joost Diepenmaat
  • 17,633
  • 3
  • 44
  • 53