Fork me on GitHub
#yada
<
2016-02-19
>
nha10:02:09

I have a bug in my stuartsierra component map It is (probably not linked to yada, but it seems the best place to ask) : it works fine until I reload it, but only the bidi routes always return Not found. The component RouteProvider/route method is not called. My component map looks like this :

::pubsub (component/using
             (backend.components.pubsub/make-api) ;; this is only called once
             [::datomic ::subscriber-store])

   ::router (component/using
             (modular.bidi/new-router)
             [::pubsub])

   ::server (component/using
             (modular.aleph/new-webserver
              :port 10000
              :raw-stream? true
              :join? false)
             {:request-handler ::router})
Am I missing something obvious ?

nha10:02:54

(maybe unrelated) Any reason why this fails ? : (schema.core/check bidi.schema/RoutePair [true (yada "ok")])

jethroksy12:02:42

@nha: fwiw I just checked and get the same error as you

nha13:02:46

@jethroksy: thanks for the confirmation (I assume you talk about the schema check)

jethroksy13:02:02

I've looked at bidi's schema definitions

jethroksy13:02:26

yada's part doesn't look like it matches Matched

nha13:02:56

I don't know why though, a simple {} works

nha13:02:12

(Well it doesn't seem to disturb yada anyway)

jethroksy13:02:30

I'm not very clear what s/=> really does

jethroksy13:02:41

not a schema user (yet)

nha13:02:47

(not really a full time clojure programmer yet 😛 )

jethroksy13:02:14

(not really a programmer yet 😞)

jethroksy13:02:05

I guess it's just that bidi doesn't like the map that yada generates

nha13:02:12

Alright, thanks for digging simple_smile

nha16:02:37

(I'm just realizing now... not really a programmer ? what will it be when you're one then ? 😛 )

jethroksy16:02:11

@nha can't say I've gotten any actual work done at all xD

jannis17:02:48

Hi. I'm trying to serve a web app with public resources like index.html and app.js using yada and bidi.ring. The resources are in public/index.html etc. in the uberjar. However, when I do

(def routes
  ["/" (yada (new-classpath-resource "public"))])
 
all get all kinds of cryptic errors and nothing served at all. I thought perhaps serving a directory would be problematic because there is no notion of that in classpath. But it seems like it should work according to @malcolmsparks' post here: https://twitter.com/malcolmsparks/status/694826897239359488

jethroksy17:02:57

@jannis: I got the same error as you

jannis17:02:15

And at /index.html I get this NullPointerException: https://gist.github.com/Jannis/acf7e99c1771106629b0

jethroksy17:02:15

didn't manage to get it fixed

jethroksy17:02:12

there was some discussion on it but it got cleared out by slack

jannis17:02:05

Yep, I saw that discussion.

malcolmsparks17:02:27

The hsts and content policy commit has been causing people problems. I'll cut a new release now that comments out that new interceptor - apologies fot the issue. Everything seemed to 'work on my machine'

jannis18:02:05

@malcolmsparks: Is that something I can revert locally to see if it works afterwards?

malcolmsparks18:02:29

Yes. Comment out the call to sec/headers in yada.handler. Release is 15 mins away...

malcolmsparks18:02:50

Not something I can do from my phone yet!

jannis18:02:57

No problem simple_smile

jannis18:02:59

I'll try that

malcolmsparks18:02:15

@jethroksy yada does currently take over matching bidi maps. That experiment has been troublesome, so reverting that too

jannis18:02:11

It looks like my classpath resource errors are not related to the headers from yada.security.

malcolmsparks18:02:24

new release is now on clojars 1.1.0-20160219.181822-27

malcolmsparks18:02:49

@jannis - to use a classpath resource you need a path info (extra path in the URI beyond that which is matched by bidi)

malcolmsparks18:02:29

the classpath resource will match on a bidi pattern, and any remaining path is then called 'path-info'. That path-info is added to the classpath-resource's prefix config in order to determine the final resource

malcolmsparks18:02:45

It looks like you're not using classpath-resource properly (but I'm guessing based on your stack trace)

malcolmsparks18:02:49

Can you send me more info?

malcolmsparks18:02:55

I'll be able to take a more educated guess

malcolmsparks18:02:16

classpath-resource is new (I find it very useful) but has some rough edges I need to smooth down

jannis18:02:31

(def routes
  ["/" (yada (new-classpath-resource "public"))])
is how I set up the route(s). Isn't that pretty much the same as your /jar example on Twitter?

jannis18:02:11

I dumped the path info in yada and it's:

path-info index.html
path      publicindex.html
so I'm at least missing a trailing slash in "public".

malcolmsparks18:02:14

so for /index.html, bidi will match the / and set path-info to 'index.html`

malcolmsparks18:02:21

so the resource is publicindex.html

malcolmsparks18:02:33

I guess you want it to be public/index.html

malcolmsparks18:02:38

so add a / to public and it should work

malcolmsparks18:02:17

slashes are often a problem, I don't believe adding logic to yada to 'fix' them would make things simpler

malcolmsparks18:02:06

(def routes
  ["/" (yada (new-classpath-resource "public/"))])

malcolmsparks18:02:13

^ that's what you need

jannis18:02:43

-> NullPointerException in (.getProtocol res). -> "Protocol not supported".

jannis18:02:17

The path is correct now, i.e. public/index.html.

malcolmsparks18:02:10

ah, I've only tested against file-based resources on the classpath

malcolmsparks18:02:28

are you trying to serve up jar resources via http?

malcolmsparks18:02:15

I suggest creating your own classpath-resource version (the code is in yada.resources.classpath-resource)

malcolmsparks18:02:19

and having a play around

malcolmsparks18:02:40

this is just a normal yada resource, nothing 'built-in' to yada to support this use csae

jannis18:02:43

Yep. I'm building an uberjar that I then deploy to a server. The uberjar runs a web server that serves resources from within the jar via bidi.ring and yada.

malcolmsparks18:02:05

I haven't tried that

malcolmsparks18:02:15

It looks like it's possible, but via a difficult algo

malcolmsparks18:02:50

the classpath-resource code does some clever stuff by trying to find the actual jar file

jannis18:02:08

How are you doing the /jar example from twitter then? That's serving a classpath resource via HTTP as well, isn't it?

malcolmsparks18:02:45

I'm not using uberjars though

malcolmsparks18:02:21

http://yada.juxt.pro is just leiningen fronted with nginx

malcolmsparks18:02:39

But I'm keen to support your usecase

malcolmsparks18:02:16

Let me try to replicate your usecase via uberjar

jannis18:02:07

Yeah, it would be cool to have this supported. Serving static resources from uberjars is a pretty standard deployment strategy. Well, at least in development deployments. In production you'd probably use a CDN for anything static.

jannis18:02:51

I'd expect io/resource to return something useful already because it should operate against the uberjar classpath. So perhaps you're right and this is a case of simplifying the current classpath resource implementation.

malcolmsparks18:02:02

i'll see if I can make the existing code support uberjar resource serving

jannis18:02:09

The jar file resolution shouldn't be necessary in this case.

jannis18:02:20

I'm doing the same thing as we speak 😉

malcolmsparks18:02:27

right - perhaps we should have a separate resource for that, like 'jar-resource'

jannis18:02:19

Could make sense. When I see "classpath" anywhere, I'm always assuming it's refering to the classpath of the jar I'm running, not external jars or dependency jars.

jannis18:02:23

Setting the prefix to "" and typing in gives me the following resource: #object[java.net.URL 0x4209584d file:/home/jannis/.boot/cache/tmp/home/jannis/Work/myapp/myapp/7w3/-rcsl8f/public/index.html]. That looks about right and should be ready to be served.

jannis18:02:53

And it works

malcolmsparks18:02:24

I've managed to get to the same NullPointerException as you had earlier

jannis18:02:26

@malcolmsparks: Would you accept a pull request that renames the current classpath resource to jar-resource or external-jar-resource and adds a new classpath-resource that serves files from the jar itself?

malcolmsparks18:02:09

yes, but I might consider renaming the latter too

jannis18:02:29

Ok, what name would you like it to have?

malcolmsparks18:02:32

for me, classpath is not a single jar but a list of jars

malcolmsparks18:02:44

(I'm a ex-Java hacker)

malcolmsparks18:02:58

uberjar-resource ?

jannis18:02:11

Me too. Although last time I touched Java was in 2007 or so. 😉

malcolmsparks18:02:19

are you assuming in your new resource that classpath is a single jar?

malcolmsparks18:02:23

(java.class.path)

jannis18:02:26

That's not even true, I worked on Android stuff a while ago.

jannis18:02:47

I'm not assuming anything, I'm just using whatever io/resource thinks classpath is. Which I think includes all dependencies.

malcolmsparks18:02:21

right - that's ok then, call it classpath-resource as you suggest

malcolmsparks18:02:44

yes, send the PR and I'll accept

jannis18:02:44

Cool, thanks simple_smile

jannis19:02:25

-> #object[java.net.URL 0x76f3252a jar:file:/home/jannis/.m2/repository/metosin/ring-swagger/0.22.4/ring-swagger-0.22.4.jar!/META-INF/maven/metosin/ring-swagger/pom.properties]. So yes, it can access pretty much anything available in the classpath.

jannis19:02:28

This isn't even from an uberjar. I'll try that as well but it should just bundle all those jars together and make the files available in the single jar. It should work equally.

jannis19:02:40

I'll cook up something clean and send you a PR for review.

malcolmsparks19:02:56

perfect, thanks

malcolmsparks19:02:05

all these improvements add up

jannis19:02:28

I hope it still works! Haven't updated it in a while.

malcolmsparks19:02:49

very brave doing this in om next simple_smile

malcolmsparks19:02:09

there's so few resources out there still, real code is rare

jannis19:02:46

That's true. I'm working with a couple of startups who are going all-in with Om Next though and they are not the only ones. It's gaining a lot of attraction in real product development already.

malcolmsparks19:02:10

btw. I'm trying to make yada as om next friendly as I can

malcolmsparks19:02:28

yes, om next seems to be a new wave already!

malcolmsparks19:02:38

are you going to clojure d this weekend?

jannis19:02:03

I found out about yada through that post. Very nice!

malcolmsparks19:02:49

yada is a lot older than om next 😉

malcolmsparks19:02:21

i'm somewhat slower than mr. nolen

jannis19:02:57

Hehe. If it proves reliable enough I'll definitely consider using it with Om Next. The om-next-query-resource idea looks great!

jannis19:02:02

Who isn't? 😉

jannis19:02:46

I was thinking of attending ClojureD but I won't make it. Just relocated and still busy setting up and all.

jannis19:02:49

Are you going?

nha21:02:34

When doing :

(def r ["/api/" [["a" (yada "AAA")]
                   ["b" (yada "BBB")]]])
  (match-route r "/api/a")
I get an error java.lang.IllegalArgumentException: No implementation of method: :resolve-handler of protocol: #'bidi.bidi/Matched found for class: yada.handler.Handler (same error I get on my routes). How should I solve it ?

dominicm21:02:49

I'm pretty sure yada is supposed to add matchers for bidi.

nha22:02:52

Well - I thought it would - but I get this error now from aleph when requesting a page, and this above inthe repl

dominicm22:02:11

Yeah, I know it's been altered slightly recently.. so maybe the change was excessive.

nha22:02:33

Hmm alright I'll try reverting to an older version

nha22:02:41

Thanks - time to sleep 😛