Fork me on GitHub
#yada
<
2016-09-20
>
kingoftheknoll02:09:26

Lol I said for the ‘file of me’. I meant for the life of me.

dominicm08:09:52

@kingoftheknoll:

["" (yada/as-resource (io/resource "public"))]
I think that should work

kardan09:09:01

Is there a difference from ["" (bidi/->ResourcesMaybe {:prefix “public/"})] ?

kardan09:09:44

Ah didn’t know that

dominicm09:09:08

Me neither 😄. I usually just assume yada is smarter.

malcolmsparks12:09:02

Yada resources tend to be superior to bidi's ring handler: they have more metadata to work from, benefit from the async interceptor model and are more scaleable while being more http friendly

kingoftheknoll14:09:33

@dominicm thanks. If that’s the case then the manual in everyplace it talks about serving an index.html file it’s incorrect. https://juxt.pro/yada/manual/index.html#_declaring_your_website_or_api_as_a_bidi_yada_tree

dominicm15:09:24

@kingoftheknoll It's still correct and valid here:

["index.html"
   {:summary "A list of the products we sell"
    :methods
    {:get
     {:response (file "index.html")
      :produces "text/html"}}}]
although does make the assumption that the file is relative to where your jar runs, so (io/resource "index.html") might be better here. It's more verbose, but is definitely correct (imo)

dominicm15:09:37

If you want a Summary (for swagger this is a way to do it.)

kingoftheknoll15:09:02

if you search the file for “index.html” you’ll find that same example used 3 times.

dominicm15:09:56

Hmm, I only see that one. And (yada/handler (new java.io.File "index.html"))

kingoftheknoll16:09:29

I’m sorry 2 times. ^ that is the second. That one didn’t work for me either. I’m guessing for the same reason.

dominicm16:09:15

@kingoftheknoll Does it not work in your project you mean?

kingoftheknoll17:09:55

excuse me, yes. It’s probably that I just don’t understand how to use java.io.File. I had attempted (yada/handler (new java.io.File “public/index.html”)) which is where my html file was in my resources dir.

kingoftheknoll17:09:10

And I tried (yada/handler (io/file "public/index.html”)) where I aliased the namespace.

dominicm17:09:05

ah. Yeah, it's a bit confusing. Took me a long time to figure it out.

dominicm17:09:04

(io/file "resources/public/index.html") will work in development, if you start in the right location. Most production targeted applications will want to use (io/resource) and pull the file off the classpath.

dominicm17:09:22

Understanding the distinction between a file and a resource is the key here I think.

malcolmsparks17:09:40

For those of you (like us) using yada and itching to try the clojure.spec kool aid: https://twitter.com/juxtpro/status/778291184250880000

malcolmsparks18:09:21

@kingoftheknoll I've been on client site today, sorry about the issue you've been having with (yada/as-resource (io.file ...)) - I gather from the thread that the problem isn't so much serving the file but the fact that in deployment the file doesn't exist on the working directory (or rather, it's in the uberjar). Is that right? This is a thing with Java, files are always relative to the current working directory, resources are on the classpath (or in the uberjar if you've deployed one)

malcolmsparks18:09:10

In the beginning (1995) there were only directories full of class files. Then Sun invented the JAR (because HTTP connections didn't have keep-alive and each class downloaded to the browser took ages, even over those amazing 28.8K modems we had. Then they invented 'resources', which allowed you to access things in the classpath. But there were still files too.

malcolmsparks18:09:46

Then Clojure came along and they invented uberjars (because they'd already used JARs to ship Clojure source code and needed somewhere to put all the aot compiled code)

kingoftheknoll18:09:36

@malcolmsparks that makes a lot of sense. Like you said what I’m lacking in context having clojure be my first real introduction to the Java ecosystem. Thanks for laying it out for me!