Fork me on GitHub
#ring
<
2021-03-25
>
cschep04:03:33

sorry if this isn’t the right place, but I’ve got some compojure routes like so

(defroutes routes
  (GET "/" [] (index/index))
  (route/resources "/")
  (route/not-found "oh no"))

cschep04:03:49

i’ve got some static assets in resources/public

cschep04:03:56

and they are 404'ing

cschep04:03:09

is it laid out somewhere what directory to use?

seancorfield04:03:00

Hmm, I thought the default was public on the classpath. Ah, how are you starting/running your app? Leiningen or Clojure CLI?

seancorfield04:03:05

I can't remember whether lein puts resources on the classpath by default but deps.edn certainly doesn't -- you need to set :paths ["src" "resources"] in your deps.edn.

cschep04:03:13

clj -M -m schepball.main

cschep04:03:22

with a pretty bare deps.edn

cschep04:03:27

i was wondering how the tool knew where to look

cschep04:03:40

maybe “resources” was a magic jvm directory or something

cschep04:03:57

is src in deps.edn by default?

cschep04:03:05

{:deps
 {org.jsoup/jsoup {:mvn/version "1.13.1"}
  dk.ative/docjure {:mvn/version "1.14.0"}
  compojure/compojure {:mvn/version "1.6.2"}
  ring/ring {:mvn/version "1.9.2"}}}

cschep04:03:11

this is my entire deps.edn

cschep04:03:39

but i have code in src

cschep05:03:54

that fixed it thank you!!

seancorfield05:03:04

Yes, "src" is the default value for :paths. If you need additional directories, you need to specific (all of) them in your project deps.edn, so :paths ["src" "resources"] would need to be added.

seancorfield05:03:17

You can see it reflected in the classpath here:

[email protected]:~/clojure$ clojure -Spath
# just src on the path (plus Clojure's libs):
src:/home/seanc/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/home/seanc/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/home/seanc/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar
[email protected]:~/clojure$ clojure -Sdeps '{:paths ["src" "resources"]}' -Spath
# now we have src and resources on the path:
src:resources:/home/seanc/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/home/seanc/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/home/seanc/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar