Reputation: 5438
I'm using catnip/leiningen in an attempt to learn Clojure... So I have a simple website and now I'd like to add a clojure-script in my page.
So I took a simple example but now got stuck on how to access my script from my site.
My project.clj
(defproject hello-world "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.1.5"]
[hiccup "1.0.2"]]
:plugins [[lein-ring "0.8.2"]]
:cljsbuild {:builds
[{:source-path "src"
:compiler
{:output-to "resources/public/cljs/main.js"
:output-dir "resources/public/cljs"
:optimizations :simple
:pretty-print true}}]}
:ring {:handler hello-world.handler/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]]}})
Relevant part of handler.clj
(defn header [title]
(html
[:head
[:title title]
[:script "/cljs/play.js"]]))
If I run lein ring server there are nothing at http://localhost:8080/resources/public/cljs/main.js
. How to map the requests for js so that my site can find them?
Upvotes: 0
Views: 364
Reputation: 5438
The problem is in the [:script]-tag that needed to be rewritten to either:
[:script {:src "/cljs/main.js"}]
or
(include-js "/cljs/main.js")
to generate a corrent link to the javascript-file.
Upvotes: 1
Reputation: 20934
Your JavaScript file should be accessible under http://localhost:8080/cljs/main.js
not http://localhost:8080/resources/public/cljs/main.js
. Your actual code looks to be ok otherwise.
Did you run lein cljsbuild once
and did it create a JavaScript file under /resources/public/cljs/
?
Upvotes: 0