Fork me on GitHub

Hi guys, looking for a bit of help with this piece of code

(defn resource-routes []
     [["/" (yada/handler (file "app.html"))]
      ["/" (yada/handler (resource "/resources/"))]]]
    {:port 5000}))
I’m building a very simple website (a single page to be precise) but I am having trouble getting yada to serve up the files in resources/public/… directory, I’ve tired a few different approaches to the above but thats were I currently left it off; Working with the webpage directly for the mean time. Also on top of that, what is the correct way to shutdown the server. As per the documentation I call ((:close (resource-routes))) but it returns CompilerException Address already in use which means I cannot refresh changes without forcing closed the REPL and occasionally having to open up Activity Monitor and force close form there. What I am asking what is the best/right way to close/restart the server.


I think that should be (resource "") or maybe it should be the yada classpath resource from the namespace of the same name


I tried the (new-classpath-resource) and it didn’t work for me either, I had looked at an old response for more or less than same issue I am having and it suggested the classpath resource though that didn’t work for me.


We use it, it certainly works. But it never works how I expect it to.


using (new-classpath-resource) produces, in the browser, Failed to load resource: the server responded with a status of 404 (Not Found)


Oh, I remember how it works, try "" instead of "/" for the bidi route for your classpath resource


Oh, also don't do "/resources/", turn that to ""


Still getting 404, it’s odd why I can’t get it to work


I may have been wrong, it may be "/", as the path.


I'm afk, else I'd just spin this up and check by stepping through what it looks up


@severed-infinity what does your project.clj look like? (presuming you're using lein)


specifically, do you have anything in there specifying resource directories, or is it just the lein default


:description "FIXME: write description"
  :url ""
  :license {:name "Eclipse Public License"
            :url ""}
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.946"]

                 [hiccup "1.0.5"]
                 [aleph "0.4.4"]
                 [bidi "2.1.3"]
                 [yada "1.2.11"]

                 [reagent "0.8.0-alpha2"]
                 [re-frame "0.10.5"]]
  :plugins [[lein-cljsbuild "1.1.7"]
            [lein-figwheel "0.5.15"]]
  :main yugiohcardeffect.clj.core
  :target-path "target/%s"
  :cljsbuild {:builds [{; The path to the top-level ClojureScript source directory:
                        :source-paths ["src/"]
                        :id "main"
                        :figwheel true
                        ; The standard ClojureScript compiler options:
                        ; (See the ClojureScript compiler documentation for details.)
                        :compiler {:main yugiohcardeffect.cljs.builder
                                   :output-to "resources/public/js/main.js"  ; default: target/cljsbuild-main.js
                                   :optimizations :none
                                   :pretty-print true}}]}
  :figwheel {:ring-handler yugiohcardeffect.clj.core/start}
  :profiles {:uberjar {:aot :all}})


Definitely worth checking that (resource "public/js/main.js") returns something


^^^ Agreed. if not add :resource-paths ["resources"] to your project.clj; I can't remember off the top of my head if lein adds that by default like it does src for :source-paths


it doesn’t as thats the default except cljsbuild


Added the :resource-paths and tired (resource "public/js/main.js"), I don’t get a 404 but clicking on the file in the browser opens a about:blank page and empty file in console


@severed-infinity I meant that you should run that code in the repl :)


it returns the correct file path


Okay, good. Just checking. Switch back to classpath resource in the routes, that's definitely the way forward.


on chrome I get GET net::ERR_ABORTED while on safari I get Failed to load resource: the server responded with a status of 404 (Not Found) but beyond that I’ve not moved forwards nor backwards since yesterday just staying at this impasse.


Wait, you're going to the wrong url?


I’ve ranged from having very specific file paths to no file paths, from using file, resource, new-classpath-resource all of which produce slightly different variations of each other


It should be /public/js/main.js


Not /resources/...