This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-02-19
Channels
- # beginners (25)
- # boot (143)
- # braid-chat (9)
- # cider (18)
- # cljs-dev (88)
- # cljsrn (1)
- # clojure (91)
- # clojure-austin (2)
- # clojure-berlin (3)
- # clojure-japan (26)
- # clojure-russia (148)
- # clojurebridge (1)
- # clojured (29)
- # clojurescript (105)
- # cursive (7)
- # data-science (4)
- # datomic (15)
- # devcards (4)
- # emacs (8)
- # euroclojure (2)
- # events (1)
- # gsoc (27)
- # hoplon (3)
- # immutant (3)
- # ldnclj (3)
- # lein-figwheel (9)
- # leiningen (2)
- # luminus (1)
- # off-topic (5)
- # om (176)
- # onyx (136)
- # parinfer (16)
- # proton (13)
- # re-frame (33)
- # reagent (34)
- # spacemacs (1)
- # yada (127)
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 ?(maybe unrelated) Any reason why this fails ? : (schema.core/check bidi.schema/RoutePair [true (yada "ok")])
@jethroksy: thanks for the confirmation (I assume you talk about the schema check)
(I'm just realizing now... not really a programmer ? what will it be when you're one then ? 😛 )
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/694826897239359488At /
I get this error: https://gist.github.com/Jannis/bd0299f9bd51ec467f71
And at /index.html
I get this NullPointerException
: https://gist.github.com/Jannis/acf7e99c1771106629b0
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'
@malcolmsparks: Is that something I can revert locally to see if it works afterwards?
Yes. Comment out the call to sec/headers in yada.handler. Release is 15 mins away...
Not something I can do from my phone yet!
@jethroksy yada does currently take over matching bidi maps. That experiment has been troublesome, so reverting that too
It looks like my classpath resource errors are not related to the headers from yada.security
.
new release is now on clojars 1.1.0-20160219.181822-27
@jannis - to use a classpath resource you need a path info (extra path in the URI beyond that which is matched by bidi)
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
It looks like you're not using classpath-resource properly (but I'm guessing based on your stack trace)
Can you send me more info?
I'll be able to take a more educated guess
classpath-resource is new (I find it very useful) but has some rough edges I need to smooth down
(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?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"
.so for /index.html
, bidi will match the /
and set path-info to 'index.html`
so the resource is publicindex.html
I guess you want it to be public/index.html
so add a / to public and it should work
slashes are often a problem, I don't believe adding logic to yada to 'fix' them would make things simpler
(def routes
["/" (yada (new-classpath-resource "public/"))])
^ that's what you need
ah, I've only tested against file-based resources on the classpath
are you trying to serve up jar resources via http?
I suggest creating your own classpath-resource version (the code is in yada.resources.classpath-resource)
and having a play around
this is just a normal yada resource, nothing 'built-in' to yada to support this use csae
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.
I haven't tried that
It looks like it's possible, but via a difficult algo
the classpath-resource code does some clever stuff by trying to find the actual jar file
How are you doing the /jar
example from twitter then? That's serving a classpath resource via HTTP as well, isn't it?
I'm not using uberjars though
http://yada.juxt.pro is just leiningen fronted with nginx
But I'm keen to support your usecase
Let me try to replicate your usecase via uberjar
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.
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.
i'll see if I can make the existing code support uberjar resource serving
right - perhaps we should have a separate resource for that, like 'jar-resource'
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.
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.
I've managed to get to the same NullPointerException as you had earlier
@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?
yes, but I might consider renaming the latter too
for me, classpath is not a single jar but a list of jars
so avoid that
(I'm a ex-Java hacker)
uberjar-resource ?
are you assuming in your new resource that classpath is a single jar?
(java.class.path)
I'm not assuming anything, I'm just using whatever io/resource
thinks classpath is. Which I think includes all dependencies.
right - that's ok then, call it classpath-resource as you suggest
yes, send the PR and I'll accept
->
#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.
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.
perfect, thanks
all these improvements add up
very brave doing this in om next
there's so few resources out there still, real code is rare
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.
btw. I'm trying to make yada as om next friendly as I can
yes, om next seems to be a new wave already!
are you going to clojure d this weekend?
ah - great
yada is a lot older than om next 😉
i'm somewhat slower than mr. nolen
Hehe. If it proves reliable enough I'll definitely consider using it with Om Next. The om-next-query-resource
idea looks great!
I was thinking of attending ClojureD but I won't make it. Just relocated and still busy setting up and all.
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 ?Well - I thought it would - but I get this error now from aleph when requesting a page, and this above inthe repl
Yeah, I know it's been altered slightly recently.. so maybe the change was excessive.
@malcolmsparks: Ok, here's a PR for you: https://github.com/juxt/yada/pull/63