Fork me on GitHub
#reitit
<
2019-08-29
>
Binita Bharati07:08:17

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

jahson10:08:36

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>

jahson10:08:02

So, if the current URL is the resulting URL for script will be

Binita Bharati15:08:53

@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.

jahson17:08:55

@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.

Binita Bharati17:08:50

@jahson - Thanks. Its working now. I moved all referred directories (`vendor`) to be directly under public directory.

👍 8