yada

2018-03-20T22:19:50.000056Z

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

(defn resource-routes []
  (yada/listener
    [""
     [["/" (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 java.net.BindException: 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.

dominicm 2018-03-20T22:21:57.000041Z

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

2018-03-20T22:25:05.000156Z

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.

dominicm 2018-03-20T22:27:00.000119Z

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

2018-03-20T22:27:05.000268Z

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

dominicm 2018-03-20T22:28:21.000386Z

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

dominicm 2018-03-20T22:34:16.000417Z

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

2018-03-20T22:37:30.000404Z

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

dominicm 2018-03-20T22:39:41.000044Z

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

dominicm 2018-03-20T22:40:02.000375Z

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

tanzoniteblack 2018-03-20T22:41:07.000345Z

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

tanzoniteblack 2018-03-20T22:41:26.000344Z

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

2018-03-20T22:43:25.000185Z

:description "FIXME: write description"
  :url "<http://example.com/FIXME>"
  :license {:name "Eclipse Public License"
            :url "<http://www.eclipse.org/legal/epl-v10.html>"}
  :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}})

dominicm 2018-03-20T22:44:46.000275Z

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

tanzoniteblack 2018-03-20T22:45:28.000259Z

^^^ 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

2018-03-20T22:45:53.000369Z

it doesn’t as thats the default except cljsbuild

2018-03-20T22:53:25.000002Z

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

dominicm 2018-03-20T23:34:14.000296Z

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

2018-03-20T23:38:03.000129Z

ah

2018-03-20T23:39:00.000188Z

it returns the correct file path

dominicm 2018-03-20T23:40:47.000027Z

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

2018-03-20T23:44:33.000081Z

on chrome I get GET <http://localhost:5000/resources/public/js/main.js> 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.

dominicm 2018-03-20T23:46:09.000175Z

Wait, you're going to the wrong url?

2018-03-20T23:46:14.000234Z

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

dominicm 2018-03-20T23:46:28.000145Z

It should be /public/js/main.js

dominicm 2018-03-20T23:46:35.000059Z

Not /resources/...