Fork me on GitHub
#yada
<
2018-03-20
>
severed-infinity22:03:50

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.

dominicm22:03:57

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

severed-infinity22:03:05

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.

dominicm22:03:00

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

severed-infinity22:03:05

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

dominicm22:03:21

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

dominicm22:03:16

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

severed-infinity22:03:30

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

dominicm22:03:41

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

dominicm22:03:02

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

tanzoniteblack22:03:07

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

tanzoniteblack22:03:26

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

severed-infinity22:03:25

: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}})

dominicm22:03:46

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

tanzoniteblack22:03:28

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

severed-infinity22:03:53

it doesn’t as thats the default except cljsbuild

severed-infinity22:03:25

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

dominicm23:03:14

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

severed-infinity23:03:00

it returns the correct file path

dominicm23:03:47

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

severed-infinity23:03:33

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.

dominicm23:03:09

Wait, you're going to the wrong url?

severed-infinity23:03:14

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

dominicm23:03:28

It should be /public/js/main.js

dominicm23:03:35

Not /resources/...