Adding static files to compojure

57 Views Asked by At

I need to add leaningen project

my-compojure/src/dist/output.css

from tailwind to my compojure project. Where should I put it?

After starting the server, I am naively calling

localhost:3000/dist/output.css

But that does not work.

Does anybody know, how I can add these static files in compojure?

1

There are 1 best solutions below

0
user2609980 On

You need to serve the static files from your server. When using Leiningen you can place the file in the resources/public folder in the root. Ensure the project.clj points to the resource folder with :resource-paths ["resources"]. Then serve the resources folder using Compojure:

(:require [ring.middleware.resource :refer [wrap-resource]])

(def app
  (wrap-resource approutes "public")) ; serve static files from "resources/public"

(def server (run-jetty #'app {:join? false, :port 3000}))

See Serve static resources using Clojure's Ring for a more elaborate example.