Fork me on GitHub

How do I serve static files?


I can't really find much online


there is also ::file-path

👍 4
Ahmed Hassan05:05:55

Which of these is used to serve JavaScript script files like main.js?


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

✔️ 4
Ahmed Hassan12:05:11

Bundle of thanks. It works. 🙂

Ahmed Hassan12:05:04

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

✔️ 4