reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
coby 2020-04-12T06:26:17.097900Z

I'm struggling to get static resources working with reitit and http-kit. Requesting / returns the expected "ok!" response but requesting /js/app.js (which is definitely there, in the public dir) returns the 404 Not Found response:

(ns rtc.server
  (:require
   [org.httpkit.server :as http]
   [reitit.ring :as ring]))

(defn handler [_]
  {:status 200
   :headers {"Content-Type" "text/html; charset=utf-8"}
   :body "ok!"})

(def app (ring/ring-handler
          (ring/router
           [["/" {:get handler}]
            ["/ping" (constantly {:status 200 :body "ok"})]])
          (ring/routes
           (ring/create-resource-handler {:path "/"})
           (ring/create-default-handler
            {:not-found (constantly {:status 404
                                     :headers {"Content-Type" "text/plain; charset=utf-8"}
                                     :body "Not Found"})}))))

(defonce stop-fn (atom nil))

(defn start [& [opts]]
  (let [port (:port opts 3000)]
    (reset! stop-fn (http/run-server app {:port port})))
  nil)
Any tips for how to debug?

ikitommi 2020-04-12T06:33:52.099300Z

@ctamayo hi, so you have /resources/public/js/app.js defined?

coby 2020-04-12T06:43:19.100600Z

the file lives at /public/js/app.js , there's no resources dir in this project. Is that the issue?

ikitommi 2020-04-12T08:32:41.102600Z

resource-handler reads files from classpath, a convention is to use resources folder for that.