Fork me on GitHub
#yada
<
2016-09-17
>
iwillig13:09:42

Hey Yada channel, trying to serve some static files with yada 1.1.33 with the follow code

iwillig13:09:44

(yada/as-resource (io/file “out”))

iwillig13:09:52

and i am getting the following error

iwillig13:09:05

clojure.lang.ExceptionInfo: Cannot turn resource-model into resource, because it doesn't conform to a resource-model schema {:resource-model nil, :error {:methods missing-required-key}}

iwillig13:09:19

i think i am missing something

malcolmsparks14:09:33

Does out exist?

malcolmsparks14:09:51

as-resource behaves differently if the file given is a file or directory. I wonder if the fact it may not exist is the problem

iwillig15:09:23

good question

iwillig15:09:53

(.exists (io/file "out”))

iwillig15:09:35

does out need to be in resource

malcolmsparks16:09:08

No. It doesn't. What does (.isDirectory (io/file "out")) report?

iwillig16:09:56

easy-map.server> (.isDirectory (io/file "out"))
true
easy-map.server> 

malcolmsparks18:09:56

it works for me on 1.1.33 (that's never a satisfactory answer, I know, so I wonder what is going on in your situation @iwillig )

malcolmsparks18:09:19

could you have overridden ResourceCoercion for java.io.file ?

iwillig18:09:27

i don’t think so

iwillig18:09:34

sorry i should have explained a little more

iwillig18:09:48

the error only happens when i am attempt to make a request

iwillig18:09:04

{:path-info? true,
 :produces
 [{:media-type
   {:name "text/plain",
    :type "text",
    :subtype "plain",
    :parameters {},
    :quality 1.0}}
  {:media-type
   {:name "text/html",
    :type "text",
    :subtype "html",
    :parameters {},
    :quality 1.0}}],
 :error-interceptor-chain
 [#function[yada.security/access-control-headers]
  #function[yada.interceptors/create-response]
  #function[yada.interceptors/logging]
  #function[yada.interceptors/return]],
 :methods
 {:get
  {:response
   #function[yada.resources.file-resource/eval42586/new-directory-resource--42591/fn--42595/fn--42597]}},
 :interceptor-chain
 [#function[yada.interceptors/available?]
  #function[yada.interceptors/known-method?]
  #function[yada.interceptors/uri-too-long?]
  #function[yada.interceptors/TRACE]
  #function[yada.interceptors/method-allowed?]
  #function[yada.interceptors/parse-parameters]
  #function[yada.interceptors/capture-proxy-headers]
  #function[yada.security/authenticate]
  #function[yada.interceptors/get-properties]
  #function[yada.security/authorize]
  #function[yada.interceptors/process-request-body]
  #function[yada.interceptors/check-modification-time]
  #function[yada.interceptors/select-representation]
  #function[yada.interceptors/if-match]
  #function[yada.interceptors/if-none-match]
  #function[yada.interceptors/invoke-method]
  #function[yada.interceptors/get-new-properties]
  #function[yada.interceptors/compute-etag]
  #function[yada.security/access-control-headers]
  #function[yada.security/security-headers]
  #function[yada.interceptors/create-response]
  #function[yada.interceptors/logging]
  #function[yada.interceptors/return]],
 :sub-resource
 #function[yada.resources.file-resource/eval42586/new-directory-resource--42591/fn--42595/fn--42600]}

iwillig18:09:09

strange @malcolmsparks okay i will look into this a little more..

iwillig18:09:38

not sure if this would effect it but here are the libs on my class path

iwillig18:09:42

(defproject easy-map "0.0.0"

  :description ""
  :url ""
  :license {:name ""
            :url ""}

  :dependencies [[aero "1.0.0"]
                 [org.clojure/tools.logging "0.3.1"]
                 [com.taoensso/timbre "4.7.0"]

                 [org.clojure/clojure "1.8.0"]
                 [im.chit/hara "2.4.0"]

                 [funcool/suricatta "1.1.0"]

                 [cheshire "5.6.3"]
                 [migratus "0.8.29"]
                 [com.layerware/hugsql "0.4.7"]
                 [org.postgresql/postgresql "9.4.1207"]
                 [hikari-cp "1.7.1"]

                 [funcool/cats "2.0.0"]
                 [prismatic/schema "1.0.5"]

                 [bidi "2.0.10"]
                 [yada "1.1.33"]
                 [aleph "0.4.1"]

                 [mount "0.1.10"]
                 [org.clojure/tools.namespace "0.2.11"]
                 [buddy/buddy-hashers "0.14.0"]
                 [buddy/buddy-sign "1.1.0" :exclusions [org.clojure/tools.reader]]

                 [hiccup "1.0.5"]]

  :profiles {:dev {:source-paths ["dev" ]
                   :dependencies [[org.clojure/tools.nrepl "0.2.11"]
                                  [ring/ring-mock "0.3.0"]
                                  [clj-http "2.2.0"]
                                  [juxt/iota "0.2.3"]
                                  [helpshift/hydrox "0.1.15"]]}})

malcolmsparks18:09:25

If you clone yada, do a lein repl, then (dev), (go) and goto localhost:8090/dir/ or localhost:8090/talks/ in a browser then you can see file directory serving

iwillig18:09:51

okay, i will do that but i have to run right now

iwillig18:09:59

thanks again malcolmsparks

malcolmsparks18:09:04

also edge has this construction in web_server.clj: `(-> (yada/as-resource (io/file "target")) (assoc :id :edge.resources/static))`

malcolmsparks18:09:25

ok @iwillig - keep sending me stuff and I'll keep trying to suggest things to try

malcolmsparks18:09:54

it's pretty straight-forward to serve a directory of resources, your code looks right to me

iwillig19:09:25

maybe its something wrong with my routes?

iwillig19:09:27

(mount/defstate server
  :start (yada/listener
          ["" [["/" (index)]
               ["/v1/"
                [["datasets"
                  [["" (datasets)]
                   ["/" [[[:dataset-id] (dataset)]]]]]]]
               ["" (yada/as-resource (io/file "out"))]
               [true (yada/yada nil)]]]
          {:port 3000})

  :stop ((:close server)))

iwillig20:09:51

hey @malcolmsparks i think i might figure out…

iwillig20:09:40

if f is nil we return a (resource nil)

iwillig20:09:19

which i do not think will work and when i do (yada/resource nil) in the repl i get the same error that i am seeing in the response

iwillig20:09:34

with the baby right now but i could do a pull request later if you want

kingoftheknoll21:09:16

I wanted to play with clojure.spec with my project today and I ran into a few problems with libs not conforming to specs. Upgrading Aleph to [aleph "0.4.2-alpha8”], which I can do, solves one error. But I can’t upgrade to ring-swagger to [metosin/ring-swagger "0.22.10”] where they fixed the bug there.

malcolmsparks21:09:46

@kingoftheknoll scroll up to yesterday's discussion!

malcolmsparks21:09:14

@iwillig (yada/resource nil) would be cause an error yes.

malcolmsparks21:09:03

got it! thanks for the bug report

kingoftheknoll21:09:07

@malcolmsparks very timely it seems lol. BTW love the Black Adder reference. Even though I’m in the states, I grew up watching it on PBS. That and Red Dwarf, which sadly is such a quotable show yet no one knows what I’m quoting!

dominicm22:09:17

@kingoftheknoll: better make myself look big!

kingoftheknoll23:09:02

@dominicm: no joke I did Cat's episode 1 monologue for an elementary school talent show. Was put on the spot and it was the only thing I could think of on short notice lol