This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-01-16
Channels
- # beginners (115)
- # boot (13)
- # boot-dev (13)
- # chestnut (1)
- # cider (1)
- # clara (10)
- # cljs-dev (21)
- # cljsjs (1)
- # cljsrn (2)
- # clojure (120)
- # clojure-dusseldorf (2)
- # clojure-greece (13)
- # clojure-ireland (1)
- # clojure-italy (3)
- # clojure-nlp (3)
- # clojure-russia (2)
- # clojure-spec (13)
- # clojure-uk (82)
- # clojured (5)
- # clojurescript (47)
- # core-async (2)
- # core-logic (8)
- # cursive (45)
- # datomic (2)
- # editors (1)
- # emacs (39)
- # fulcro (166)
- # graphql (1)
- # hoplon (16)
- # keechma (5)
- # off-topic (202)
- # perun (4)
- # protorepl (7)
- # re-frame (28)
- # reagent (13)
- # ring (27)
- # ring-swagger (16)
- # rum (1)
- # shadow-cljs (25)
- # spacemacs (20)
- # sql (141)
- # yada (4)
Hello everyone. I'm trying to figure out the serving of static files (e.g. css / js) within compojure. My current understanding is that I should be making use of the compojure.route/resources
function. I've defined (route/resources "/")
inside of my (defroutes app ...
declaration. I also added (app {:uri "/public/main.css" :request-method :get})
after the defroutes
function. If I try browsing to
, I keep getting the route/not-found
route.
You put main.css
in resources/public/
in your project?
(and remove /public
from the URL)
I believe the default behavior for (route/resources "/")
is to assume resources/public/
as the root for assets?
> I also added (app {:uri "/public/main.css" :request-method :get})
after the defroutes
function.
Why did you do that @yogidevbear? Just to test in the REPL what it will do?
I was reading through https://learnxinyminutes.com/docs/compojure/ which showed that usage
I didn't have the public
folder inside of resources
. Moved it and testing again now
So I have resources/public/main.css
in my example. I have (route/resources "/")
in my defroutes
, and I've removed (app {:uri "/public/main.css" :request-method :get})
. I'm still seeing page not found when trying to access
Remove /public
from that URL.
Bingo
Thanks Sean 🙂
The public
part is on the file system (so web-accessible stuff is in that folder and non-web-accessible resources such as config files are outside it).
All makes sense now that it's working
You can override that behavior by specifying a configuration option map in the route/resources
call.
In particular this part https://github.com/weavejester/compojure/blob/master/src/compojure/route.clj#L22-L23
Yup, there ya go!
Actually that's for files
, https://github.com/weavejester/compojure/blob/master/src/compojure/route.clj#L41 is for resources
So which library within Clojure knows to look inside resources
by default? Is that a Ring thing?
The compojure middleware defers to https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/util/response.clj#L320
and that uses
-- which looks on the classpath and the convention is that both resources
and src
are on your classpath in most Clojure tooling.
TIL 🙂
In a typical web app at work, we have resources/public/assets
containing css
, img
, and js
subfolders -- and URLs have /assets/css
etc -- and we have resources/templates
containing HTML files that are used as templates and rendered via Selmer (our preferred templating engine -- inspired by Django).
And we also often have resources/public/favicon.ico
for browsers 🙂
Other files in resources
include EDN config files etc.
And anything inside resources
, but outside of public
is not accessible via the browser URL field?
e.g. resources/my.edn
wouldn't be accessible from
or similar route?