Fork me on GitHub
#yada
<
2017-02-27
>
achesnais06:02:04

So I’d like to prevent yada from sending stacktraces along with 404 responses, or any response for that matter. Is there a preferred way to do this? Right now it sounds like I would have to return a custom 404 using the :responses key of the resource definition

achesnais06:02:37

but then I’d have to specifiy it for every resource and every possible response code ; which I can do with a function, but was just wondering what the best practice would be here

dominicm10:02:10

@achesnais for now I think the best way is your own app.yada/resource function

dominicm10:02:33

There's been some discussion on "profiles" in yada and having stacktraces only for dev vs prod

stijn10:02:45

or walk the bidi tree and update resources with the desired behaviour

stijn12:02:34

is it possible to make the body in a PUT/POST request optional?

stijn12:02:48

I can't figure out the schema to make it happen

sickill13:02:47

@stijn what about this:

sickill13:02:48

{:methods {:post {:parameters {(s/optional-key :body) Transaction}}}}

sickill13:02:14

nah, I don't think that would make sense

malcolmsparks13:02:42

@achesnais you could replace the event interceptor chain with your own one. Yes, these is a feature that has been requested before and profiles might be introduced soon

malcolmsparks13:02:08

It's not obligatory to declare body parameters at all.

malcolmsparks13:02:54

If yada can help you by declaring them, then great, but don't let it get in your way

sickill13:02:55

so I was trying to figure out how to make a redirect in resource's :response function

sickill13:02:02

this is what I came up with:

sickill13:02:04

(-> (:response ctx)
    (assoc :status 302)
    (update :headers assoc "location" ""))

sickill13:02:23

is this "the way" in yada?

sickill13:02:17

ok, I see yada.redirect/redirect is doing just that, cool

snorremd13:02:49

Edit: My mistake. Used :host instead of :domain in the cookie map in my tests. Hello. I'm trying to use the response-for function to test my yada resources/endpoints. It does not seem however that the function's return value contains the cookies set in the response by the resource handler. When I log the response object in the resource handler the yada.context.Response map contains them. Any way to get the cookies via response-for or do I have to figure out another way to test resources that returns cookies?

dominicm15:02:35

@sickill That looks good, if you add ring as a dependency, you can do: (merge (:response ctx) (ring.util.response/redirect ""))

sickill15:02:32

@dominicm I was thinking about that, but wasn't sure how compatible that is (ie. whether ring fns do too much/override stuff with incompatible type(s) etc)

dominicm15:02:29

@sickill We use that approach on a client project, it's more than good enough.

sickill15:02:39

perfect, thanks for the tip

sickill15:02:39

@dominicm re our discussion from last Friday about forcing specific representation via url suffix (`.png`, .gif etc). What about wrapping whole handler with a middleware that would update accept header and :uri in the request map?

sickill15:02:50

cut off .png from uri and set Accept: image/png

dominicm15:02:23

@sickill Interesting idea. It risks being a little "magic" but could definitely work.

sickill15:02:57

afaik the request map that is passed from aleph to yada/handler (or to bidi routing tree coerced to yada/handler) is just regular ring request map, right? so technically that would work (unless I modify the response, which I wouldn't here)

dominicm15:02:55

It is, yeah

sickill15:02:53

anyway, yada is awesome

sickill15:02:51

I love how it takes care of boring details, making responses more correct wrt HTTP

dominicm15:02:59

Yeah, exactly!

dominicm15:02:05

Makes me wish my browser was better

sickill15:02:04

is the yada manual source on github? I was thinking about some pull requests

malcolmsparks15:02:33

yes, it's in docs

sickill15:02:01

for ex, there's lots of talk about ETag in the manual but it doesn't mention :version property which is used for this (I eventually found it in a blog post)

sickill15:02:12

the manual also doesn't say that custom keywords in :properties map should be namespaced (it mentions namespacing in the section about resource model, but the section about properties says "anything you return will be placed in the :properties entry of the request-context", maybe it's worth repeating there that you must namespace keywords)

sickill15:02:41

(I figured that out from the 500 error message)

sickill15:02:27

if you're interested I could send a PR for these

Rachel Westmacott17:02:39

I’m struggling a bit to add basic auth (or any custom auth) to a resource handler (serving files off the filesystem) - and I have a feeling like if I can just compose the right functions that this is a trivial thing to do.

malcolmsparks17:02:48

Yes. I have 4 blogs in the pipeline all around auth. 2 are in review

malcolmsparks17:02:50

But start with the file and resources in the yada codebase: src/yada/resources/file_resource.clj

malcolmsparks17:02:46

Suggest you copy and paste, get working and then transplant your auth code into the original file resource @peterwestmacott

Rachel Westmacott17:02:03

I’ll give that a go, thanks

Rachel Westmacott19:02:28

I’ve got something that works, and its mostly a mash-up of various functions in various yada/resources namespaces

Rachel Westmacott19:02:02

I can’t help but feel that there are a lot of functions that return ‘resources’ that almost return ‘resource models’, and that if they returned ‘resource models’ they would be easier to re-use - one could simply alter the maps they return. But of course there may well be good reasons for the current design that I don’t understand. I am still getting my head around yada.

adrien20:02:25

hello sorry for the newbie question I don't understand how to handle https with yada works fine locally with http

adrien20:02:40

I just have a simple handler

adrien20:02:05

(def handler
  (yada/handler "Hello World!"))

(defn -main []
  (netty/wait-for-close
   (http/start-server handler {:port port})))

adrien20:02:32

(I haven't found an example for it)

adrien21:02:18

There is the part in the manual about HSTS, but I don't understand how to use it I'm behind an Nginx reverse proxy

adrien21:02:29

Well, looks like it was more an nginx config problem! 😅 now I do proxy_pass before I used https, and I guess that it's why aleph couldn't get it

adrien21:02:36

I should learn more about ssl and https, just to make sure it's safe to do this, and to understand why

adrien21:02:44

sorry for spamming!

stijn21:02:32

True! I've reported a bug in Google Cloud Loadbalancer because of yada's compliance with the spec.

malcolmsparks22:02:35

@peterwestmacott but you can alter yada resources, just like maps!

sickill09:02:55

I want to create my own wrapper for yada/resource and was wondering whether I should alter the map before passing to yada/resource or after. Isn't yada/resource generating interceptor chains or other model props based on input map? Or it just fills the blanks?

malcolmsparks22:02:49

@stijn cloudbleed has motivated me to look into supporting https more natively in yada/aleph. Now we cannot trust nginx...

malcolmsparks22:02:36

Publishes tomorrow noon, please keep private until then

malcolmsparks22:02:02

But any feedback welcome of course