Fork me on GitHub
#yada
<
2018-04-03
>
lsnape15:04:58

Hello, I'm having a hard time configuring yada to serve static files out of the /public directory, but relative to the server route. For example, I'd like to serve public/js/app.js at the route /js/app.js, so stripping public completely. My bidi routes look as follows:

["/" [#{"js" "css"} {true (yada/resource
                           (cp/new-classpath-resource "public"))}]]
The route is matched and the handler is called but rather than returning my file it responds with a 405.

malcolmsparks15:04:24

That 'true' looks wrong to me

lsnape15:04:43

Am I right in thinking yada performs additional matching on top of the bidi routes passed in to yada/listener?

lsnape15:04:29

Specifically for sub-resources.

malcolmsparks15:04:43

No, it doesn't do any additional matching

malcolmsparks15:04:14

Ah, I see what you mean.

malcolmsparks15:04:52

Yes, a bidi 'matched' (such as a yada resource) can decide to match on a route even if there is a 'remaining' path yet to consume. In this case, this remaining path is called the 'path-info'.

malcolmsparks15:04:07

classpath-resource makes use of this trick, so does the file/dir resources

malcolmsparks15:04:31

try having a look at edge and compare how it serves up static resources compared to your code

malcolmsparks15:04:40

usually it's just something simple

lsnape15:04:52

Aha, OK that should set me on the right path.

malcolmsparks15:04:53

{true ...} looks wrong to me

malcolmsparks15:04:07

I'm not sure what you're doing there

malcolmsparks15:04:34

what do you mean by the #{"js" "css"} ?

lsnape15:04:47

Yeah, that was bit of a fudge to get match-route to work, but now I see there's more going under the hood.

malcolmsparks15:04:59

I mean, that's OK as a pattern

malcolmsparks15:04:26

A bidi route is simply [pattern matched], where matched is a handler or vector of nested bidi routes

lsnape15:04:35

I want the routes to match files being served out of the public directory inside js and css subdirs.

malcolmsparks15:04:27

Try with 2 routes (`/js` and /css) and get that working first

malcolmsparks15:04:35

but yes, you should be able to match on a set

malcolmsparks15:04:58

[["/" #{"js" "css"}] (cp/new-classpath-resource ....)]

lsnape15:04:23

Ah gotcha. Thanks, I'll take a look at edge and let you know what I find.