Fork me on GitHub
#yada
<
2016-03-08
>
tangrammer10:03:07

Hi yada guys! unfortunately struggling again trying to extend-protocl PutResult so it returns data/body besides 204 status code this is my simple approach to do that

(defrecord MyRecordType [d])

(extend-protocol PutResult
  MyRecordType
  (interpret-put-result [o ctx]
    (assoc-in ctx [:response :body] (:d o))))

when i try this code after getting nil as response my cider or aleph freezes 😐 any ideas ?? using [yada "1.1.0-20160304.082603-32"]

malcolmsparks11:03:47

@tangrammer: can you tell if your interpret-put-result is called? is there some logging you can add?

tangrammer11:03:02

Hi Malcolm! good to have you over here simple_smile yep, I get proper logging calls I was wondering, that maybe I'm having dependency conflicts

ericfode17:03:48

@malcolmsparks: (or any other masters of yada) I have a new stack trace to divine

java.lang.IllegalArgumentException: cannot treat nil as HTTP response for request to "
	at aleph.http.server$invalid_value_response.invokeStatic(server.clj:132)
	at aleph.http.server$invalid_value_response.invoke(server.clj:129)
	at aleph.http.server$handle_request$fn__24215$fn__24216.invoke(server.clj:185)
	at manifold.deferred$fn__15596$chain_SINGLEQUOTE____15617.invoke(deferred.clj:750)
	at manifold.deferred$fn__15596$subscribe__15597$fn__15602.invoke(deferred.clj:716)
	at manifold.deferred.Listener.onSuccess(deferred.clj:219)
	at manifold.deferred.Deferred$fn__15450.invoke(deferred.clj:396)
	at manifold.deferred.Deferred.success(deferred.clj:396)
	at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243)
	at manifold.deferred$success_BANG_.invoke(deferred.clj:240)
	at manifold.deferred$catch_SINGLEQUOTE_$fn__15680.invoke(deferred.clj:959)
	at manifold.deferred.Listener.onSuccess(deferred.clj:219)
	at manifold.deferred.Deferred$fn__15450.invoke(deferred.clj:396)
	at manifold.deferred.Deferred.success(deferred.clj:396)
	at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243)
	at manifold.deferred$success_BANG_.invoke(deferred.clj:240)
	at manifold.deferred$fn__15596$chain_SINGLEQUOTE____15617.invoke(deferred.clj:737)
	at manifold.deferred$fn__15596$subscribe__15597$fn__15598.invoke(deferred.clj:710)
	at manifold.deferred.Listener.onSuccess(deferred.clj:219)
	at manifold.deferred.Deferred$fn__15450.invoke(deferred.clj:396)
	at manifold.deferred.Deferred.success(deferred.clj:396)
	at manifold.deferred$success_BANG_.invokeStatic(deferred.clj:243)
	at manifold.deferred$success_BANG_.invoke(deferred.clj:240)
	at aleph.http.server$handle_request$fn__24200$f__15079__auto____24201.invoke(server.clj:153)
	at clojure.lang.AFn.run(AFn.java:22)
	at io.aleph.dirigiste.Executor$Worker$1.run(Executor.java:62)
	at manifold.executor$thread_factory$reify__14971$f__14972.invoke(executor.clj:36)
	at clojure.lang.AFn.run(AFn.java:22)
	at java.lang.Thread.run(Thread.java:745)

ericfode17:03:39

I have tests that test the route being hit from the routing down the stack, but not hitting the http server… So I think it’s between the two.

ericfode17:03:57

Not sure where to look anymore...

ericfode17:03:21

here are the related components

(defn create-vhosts-model [api host scheme ]
  (vhosts-model
   [{:scheme (keyword scheme) :host host} 
    (:routes api)
    [true (yada nil)]]))

(defrecord ServerComponent [api port host scheme ]
  Lifecycle
  (start [component]
    (timbre/info "Starting server on " host port )
    (let [model (create-vhosts-model api host scheme )]
      (assoc component
             :vhosts-model model
             :server (http/start-server (make-handler model) {:port (read-string  port) :raw-stream? true}))))

ericfode17:03:31

also the GET endpoint at the same route works (the request in question is a POST)

malcolmsparks21:03:25

@ericfode: that stack trace is when there are no bidi matches

malcolmsparks21:03:50

My guess is that the host isn't matching

malcolmsparks21:03:10

can't help more without the api itself

malcolmsparks21:03:19

are you using bidi method guards? (you shouldn't need to with yada)

ericfode21:03:34

I don’t belive I am

malcolmsparks21:03:39

but everything looks ok to me

ericfode21:03:52

(defn  api [db]
  ["/" {"services" {"" (->  (new-service-index-resource db)
                            (assoc :id ::service-index))
                    ["/" :entry] (-> (new-service-resource db)
                                     (assoc :id ::service))}}])

malcolmsparks21:03:01

what's you host?

malcolmsparks21:03:10

you must include the port number in the host too

malcolmsparks21:03:17

e.g. localhost:8080

malcolmsparks21:03:26

could that explain it?

malcolmsparks21:03:52

that is really non-obvious

ericfode21:03:56

So I was having trouble with that when i deployed it to Cloud Foundry (think heroku), which proxies everything and ends up with no port

malcolmsparks21:03:18

that's ok, that's the purpose of host - to cope with reverse proxies

malcolmsparks21:03:38

but then localhost wouldn't match - the host has to be what's in the URI

malcolmsparks21:03:49

that's why you can add multiple host sections in a vector

malcolmsparks21:03:33

so if your site is working in dev in localhost:8080 but you deploy to http://example.org, then you must have http://example.org in your vhost

malcolmsparks21:03:23

the point of all this complexity it to allow you to forge URIs across vhosts - eventually you'll be able to import swagger definitions and forge URIs to remote services

malcolmsparks21:03:37

sorry if you've been caught out by a feature-in-progress

ericfode21:03:41

that makes sense…

ericfode21:03:49

Meh, I had a feeling i was siging up for that simple_smile

ericfode21:03:08

It’s so much better then a mess of macros, I would rather help it develop

malcolmsparks21:03:26

I've always found the whole vhost thing to be a pain with developing APIs - you get everything working fine on localhost, then everything breaks when you deploy into prod, or add a reverse proxy, etc.

ericfode21:03:05

Is there somewhere I might be able to add some better logging to yada for that sort of thing? Or do you have something planned?

malcolmsparks21:03:56

yada should have some request logging bulit-in, but doesn't yet - but yes, I have a console planned which will allow you to browse these logs (to debug, etc. )

ericfode21:03:36

Well I am glad you are working such an awesome alternative to ring/pedestal/liberator . I’ll dig into the vhosts a bit more. Thank you again for all the help