yada

dominicm 2018-03-21T09:35:02.000256Z

I noticed that your Safari exception included "/resources", which is wrong. You need to open /public/js/main.js, not /resources/public/js/main.js

dominicm 2018-03-21T09:35:19.000130Z

http://localhost:5000/public/js/main.js <-- this one

2018-03-21T15:46:25.000570Z

that work for accessing them through the URL, and reloading the page it finds some of the files. now the console produces ClojureScript could not load :main, did you forget to specify :asset-path?

2018-03-21T16:11:00.000337Z

["resources/public/" (assoc (new-classpath-resource "public") :id :yugioheffectbuilder.resources/static)] worked but its not very intuitive. looking at it I couldn’t say what it does except for the fact I had to find out from someone else

dominicm 2018-03-21T18:48:47.000441Z

That clojurescript error indicates you nees to set asset-path. If you're just learning this stuff, I recommend using edge which has clojurescript all setup for you.

2018-03-21T22:08:05.000085Z

Been using clojure for a few years now but I wouldn’t by no means call myself professional, tons I still need to learn. I don’t tend to touch Clojurescript all that much because I find its errors to be x10 more annoying than Clojure’s. This is just the first time I’ve used Yada for a project, I’ve used Bidi successfully but I didn’t use file assets for that project, it was for an API

dominicm 2018-03-21T22:15:54.000090Z

At a keyboard now, so I can help further now. (new-classpath-resource "public") this creates a yada resource which serves a directory from the classpath. For your purposes, this means it serves the "public" folder inside of resources. The route defines what URL you want to serve from. So you could serve public under "/wazoo/" if you wanted to. In this case you've chosen resources/public, I think you may have chosen resources/ because of the folder structure on your filesytem, but it's not necessary here. :asset-path in your clojurescript build config defines where clojurescript should look for the main.out files, in your case, you have to hard code it to /resources/public/main.out.

2018-03-21T22:32:34.000471Z

Changing "public/" to “resource/public/` as the URL path fixed that :asset-path issue and correctly loaded all of the files rather than just some of the files.

dominicm 2018-03-21T22:38:27.000138Z

I think that is likely the default asset path then, which I've not seen in use before.

2018-03-21T22:45:27.000112Z

I was going by Yada manual (which hasn’t been updated since January 2017) that had a small part on serving directories that only had ["route" (new-classpath-resource "directory")] and then proceeding to use the URL of the file path with no issues, at least by the documentation.

2018-03-21T22:49:37.000346Z

But I am happy that it works now

2018-03-21T22:52:47.000410Z

Now all I have to do is how to correctly start, shutdown, and reload a server as I usually get "CompilerException java.net.BindException: Address already in use"`

mccraigmccraig 2018-03-21T23:08:59.000419Z

@severed-infinity here's my aleph server start/stop stuff - https://gist.github.com/fee0055f7c492cf363e37a14170c2b22

mccraigmccraig 2018-03-21T23:09:30.000048Z

the create-aleph-server fn returns a [server stop-fn] pair, so you can see how to stop the server

2018-03-21T23:24:31.000297Z

I’m using the yada/listener function which creates an aleph server so I need to work around the listener return.

;; Copyright © 2014-2017, JUXT LTD.

(ns yada.aleph
  (:require
   [aleph.http :as http]
   [clojure.tools.logging :refer :all]
   [yada.handler :refer [as-handler]]))

(defn listener
  "Start an HTTP listener on a given port. If not specified, listener
  will be started on any available port. Returns {:port port :close fn}"
  [routes &amp; [aleph-options]]
  (let [server
        (http/start-server
         (as-handler routes)
         (merge aleph-options {:port (or (:port aleph-options) 0) :raw-stream? true}))]
    {:port (aleph.netty/port server)
     :close (fn [] (.close ^java.io.Closeable server))
     :server server}))

mccraigmccraig 2018-03-21T23:29:46.000259Z

listener is returning you the close fn in it's result map - just call that when you want to close the server

2018-03-21T23:31:07.000225Z

That is what I am doing but as I mention in my last message it returns "CompilerException java.net.BindException: Address already in use" so it would seem it is trying to start up another server

mccraigmccraig 2018-03-21T23:31:47.000159Z

can you post the code ?

mccraigmccraig 2018-03-21T23:32:16.000233Z

(your code that is)

2018-03-21T23:32:43.000145Z

yeah it’s working right now by changing it to a var than a function but here it is

(ns yugiohcardeffect.clj.core
  (:require [yada.yada :as yada]
            [yada.resources.classpath-resource :refer [new-classpath-resource]]
            [<http://clojure.java.io|clojure.java.io> :refer [file resource]]))

(def resource-routes
  (yada/listener
    ["/"
     [["" (yada/handler (file "app.html"))]
      ["resources/public/" (assoc (new-classpath-resource "public") :id :yugioheffectbuilder.resources/static)]]]
    {:port 5000}))

#_resource-routes
#_(println (resource-routes))
#_((:close resource-routes))

#_(def reload-routes
    (do
      ((:close resource-routes))
      resource-routes))

#_reload-routes

mccraigmccraig 2018-03-21T23:35:40.000070Z

my first suspicion is that ((:close resource-routes)) is returning a Deferred... hold on a min while i confirm that

2018-03-21T23:36:21.000158Z

returns #object[yada.aleph$listener$fn__22486 0x60dbe3e2 yada.aleph$listener$fn__22486@60dbe3e2] for me

2018-03-21T23:37:17.000069Z

and ((:close resource-routes)) returns nil for me

mccraigmccraig 2018-03-21T23:40:52.000133Z

oh... hold on... resource-routes is a def not a defn - what are you actually doing to reload ?

2018-03-21T23:49:08.000312Z

it was defn until about 10 minutes ago. so prior to changing to def:

(ns yugiohcardeffect.clj.core
  (:require [yada.yada :as yada]
            [yada.resources.classpath-resource :refer [new-classpath-resource]]
            [<http://clojure.java.io|clojure.java.io> :refer [file resource]]))

(defn resource-routes []
  (yada/listener
    ["/"
     [["" (yada/handler (file "app.html"))]
      ["resources/public/" (assoc (new-classpath-resource "public") :id :yugioheffectbuilder.resources/static)]]]
    {:port 5000}))

#_(resource-routes) &lt;---- first
#_(println (resource-routes))
#_((:close (resource-routes))) &lt;---- second, see if it closes

#_(def reload-routes
    (do
      ((:close (resource-routes)))
      (resource-routes)))

#_reload-routes &lt;---- last, if close works, see if I can reload
but anyway, I’d load up the repl, send (resource-routes) or resource-routes to repl. Test ((:close (resource-routes))) or ((:close resource-routes))` to see if it closes, if it does run the first again. Then lastly run reload-routes when I need to update, if part 1 and 2 work. But I find using the defn approach causes "CompilerException java.net.BindException: Address already in use".

mccraigmccraig 2018-03-21T23:55:48.000006Z

you need to store the result of (resource-routes) and then get the close fn from that result... so e.g.

(defonce server (atom nil))

(defn start! [] (reset! server (resource-routes)))
(defn stop! [] (when (:close @server) ((:close @server))))
(defn restart! [] (stop!) (start!))

mccraigmccraig 2018-03-21T23:56:10.000123Z

(there may be typos - i haven't tested that code)

2018-03-21T23:56:53.000197Z

Ah I would of assumed that resoure-routes would already be holding the result

mccraigmccraig 2018-03-21T23:57:52.000124Z

if resource-routes is a defn then it's not holding the result... if resource-routes is a def then it will be holding the result... but you probably don't want to do it that way because recompiling will redefine the var

2018-03-21T23:59:39.000183Z

yeah what you just posted is pretty much what I was looking for