Search code examples
clojureclojurescriptleiningencompojure

Serving resources from `node_modules` dir


I want to serve files from node_modules directory in project root.

so for example I added to my page this:

[:link {:href "/font-awesome/css/font-awesome.css" :rel "stylesheet" :type "text/css"}]

now I need to tell compojure to serve statically anything that's in node_modules directory, and I can't find a way.

It works if I move node_modules to resources/public dir, but I don't want that. I need to find a way to serve files from anywhere in the project directory (in this case from ./node_modules)

I tried adding :resource-paths ["node_modules"] to profiles.clj,

I tried (compojure.route/resources "node_modules" {:root "../.." }), that still didn't work.


Solution

  • This is what I did:

    added :resource-paths ["node_modules"] to project.clj - take a look at leiningen's sample

    and then (compojure.route/resources "/" {:root "" }). Seems it worked.

    upd: this apparently exposed things that should not be exposed. e.g. it's possible now to download project.clj by navigating to it in the browser. not good.

    upd 2: (compojure.route/files "/" {:root "node_modules" }) this time it's right.