This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-29
Channels
- # aleph (5)
- # announcements (2)
- # bangalore-clj (2)
- # beginners (52)
- # cider (10)
- # cljsrn (1)
- # clojure (160)
- # clojure-dev (24)
- # clojure-europe (3)
- # clojure-france (1)
- # clojure-india (1)
- # clojure-italy (3)
- # clojure-nl (6)
- # clojure-spec (13)
- # clojure-uk (51)
- # clojurescript (45)
- # code-reviews (1)
- # core-async (41)
- # cursive (41)
- # datomic (17)
- # emacs (37)
- # fulcro (42)
- # graphql (7)
- # joker (4)
- # music (1)
- # nrepl (2)
- # off-topic (21)
- # pathom (19)
- # pedestal (12)
- # re-frame (48)
- # reitit (6)
- # rewrite-clj (8)
- # shadow-cljs (41)
- # specter (6)
- # sql (21)
- # tools-deps (8)
- # vim (7)
- # xtdb (27)
Hello, I am unable to make reitit ring handler pick static references (declared for CSS/ javascript etc ) in my html . My Clojure code : `(defn handler [request]
(let [session (get request :session)
user (:user session "None")]
{:status 200
:headers {"Content-Type" "text/html"}
:body (io/input-stream (io/resource "public/home.html"))
}
)
)
(def app
(ring/ring-handler
(ring/router
[["/home" {:name ::home
:get handler
:post handler}]
;Ref - https://metosin.github.io/reitit/ring/static.html
["/assets/*" (ring/create-resource-handler)]])
(ring/create-default-handler)
))`
My html has these references : `<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src= "assets/vendor/jquery/jquery.min.js"></script>`
My directory structure under resources/public
looks like this :
`vagrant@net1mc1$ pwd
/home/vagrant/shared1/myshoppingapp/resources/public
vagrant@net1mc1:~/shared1/myshoppingapp/resources/public$ ls -lR
.:
total 24
drwxrwxrwx 1 root root 0 Aug 26 07:35 assets
-rwxrwxrwx 1 root root 11832 Aug 29 07:55 home.html
assets/vendor/bootstrap/css:
total 1348
-rwxrwxrwx 1 root root 140930 Jul 10 2018 bootstrap.min.css
assets/vendor/jquery:
total 880
-rwxrwxrwx 1 root root 86927 Jul 10 2018 jquery.min.js
`
So, the files are there. but, I am getting a 404 error for the referred CSS and JS files
The urls for these files are correct? From your example I see the path-relative (I made up the term) URLs used
<link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<script src= "assets/vendor/jquery/jquery.min.js"></script>
@jahson - Thanks for replying. My current URL: http://192.168.10.12:3000/home My original home.html content: line no 12: <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> line no 14: <script src= "assets/vendor/jquery/jquery.min.js"></script> 404 errors with the original html: ======================================= Navigated to http://192.168.10.12:3000/home home:12 GET http://192.168.10.12:3000/assets/vendor/bootstrap/css/bootstrap.min.css net::ERR_ABORTED 404 (Not Found) home:14 GET http://192.168.10.12:3000/assets/vendor/jquery/jquery.min.js net::ERR_ABORTED 404 (Not Found) ========================================= After editing my home.html as per your comments: line no 12: <link href="home/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet"> line no 14: <script src= "home/assets/vendor/jquery/jquery.min.js"></script> 404 errors with the updated html: ======================================== Navigated to http://192.168.10.12:3000/home home:12 GET http://192.168.10.12:3000/home/assets/vendor/bootstrap/css/bootstrap.min.css 404 (Not Found) home:14 GET http://192.168.10.12:3000/home/assets/vendor/jquery/jquery.min.js net::ERR_ABORTED 404 (Not Found) ========================================= So, its still giving me the 404 error.
@binita.bharati
The resource handler works with vendor/bootstrap/css/bootstrap.min.css
as path
and it delegates the response to ring.util.response/resource-handler
with :root "public"
.
The final path for resource is public/vendor/bootstrap/css/bootstrap.min.css
.
So, either provide (create-resource-handler {:root "public/assets/"})
or move everything one level up from assets
directory.
@jahson - Thanks. Its working now. I moved all referred directories (`vendor`) to be directly under public directory.