Question

Ring's file-response doesn't work for me when running from an uberjar. I've tried both

(response/file-response "index.html" {:root "resources/public"})

and

(response/response (clojure.java.io/as-file (clojure.java.io/resource "public/index.html")))

How do you serve index.html at "/" inside an uberjar?

Était-ce utile?

La solution

You'll need to use ring.util.response/resource-response which serves files found on the classpath. Assuming you want to serve an index.html file found inside a resources directory in your überjar, the arguments would be almost exactly as in your call to file-response:

(response/resource-response "index.html" {:root "public"})

It's "public" as opposed to "resources/public", because resources is one of the top-level directories included in the überjar, so public will be found on the classpath on the top level. (This would also be true if running from the filesystem instead of an überjar; the path then needs to be relative to some top-level directory on the classpath.)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top