How do I serve static files?
I can't really find much online
https://github.com/pedestal/pedestal/blob/master/service/src/io/pedestal/http.clj#L198
there is also ::file-path
Which of these is used to serve JavaScript script files like main.js
?
https://clojurians.slack.com/archives/C053AK3F9/p1559107538359200
I output my main.js
to somewhere like target/pubic/app/main.js
then I set ::http/file-path
to target/public
In the index.html
, you will import as <script src="/app/main.js">
Don't forget about ::http/mime-types mime/default-mime-types
Bundle of thanks. It works. 🙂
When I change from ::http/file-path
to ::http/resource-path
it gives error again. What is difference here?
::http/resource-path
needs to be something in your classpath. In :paths
from deps.edn
or :resource-paths
from project.clj
Example:
output main.js
in resource/public/app/main.js
resource
is in my classpath. I can test with (slurp (io/resource "public/app/main.js"))
should return my file
then I can use ::http/resource-path "public"
, my index with src="/app/main.js"
...