0.9.18 Equivalent to assets() in Groovy DSL

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

0.9.18 Equivalent to assets() in Groovy DSL

Craig Schlegelmilch
Hello,

I see that sometime between 0.9.16 and 0.9.18 the assets() function in Groovy DSL disappeared.  It appears that the replacement is the files() function.  The examples in the javadoc make sense in the context of a java application, but I can't quite seem to grok what the equivalent in the Groovy DSL would be.

Is someone able to 1) confirm that files() is indeed  the correct function to use and b) provide a simple example using the Groovy DSL?

Thanks,

Craig
rus
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

rus
Yep, files is the replacement.  A simple usage would be

    files { dir "public" }
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Craig Schlegelmilch
Sorry to bump this, but a related problem/question:  Is there a way in the DSL to embed files() inside a path()?  I want to do this:

path ("::(css|fonts|images|js).*") {
        files { dir "public" }
}

path() is capturing the request, but it fails with:
[ratpack-compute-1-2] WARN ratpack.server.internal.NettyHandlerAdapter - No response sent for GET request to /css/std.css (last handler: closure at line 115 of file:///  . . . .



Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

danhyun
What does the structure of your public directory look like?
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Craig Schlegelmilch
In this case, there are directories that match the regex in the path():

public
css
fonts
images
js

Then there are subdirectories beneath most of these.


On Aug 2, 2015, at 7:15 AM, danhyun [via Ratpack Forum] <[hidden email]> wrote:

What does the structure of your public directory look like?


If you reply to this email, your message will be added to the discussion below:
http://forum.ratpack.io/0-9-18-Equivalent-to-assets-in-Groovy-DSL-tp1181p1194.html
To unsubscribe from 0.9.18 Equivalent to assets() in Groovy DSL, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

danhyun
So path will out right match the entire path. I think you're looking for something more like:
prefix("::(css|fonts|images|js)") {
  files {
    dir "public"
  }
}
But even this will force you to request assets like /css/css/std.css vs /css/std.css

The same asset would be served for /(css|fonts|images|js)/css/std.css.

If you do wish to serve css as /css this should suffice.

files { dir "public" }
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

danhyun
Also feel free to join us in our slack channel http://slack-signup.ratpack.io/
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Luke Daley
Administrator
I'm having a little trouble understanding exactly what you're trying to do and why.

Is it that you only want to serve a subset of the contents of the “public” dir? Or are you looking for a straight up replacement for assets(String) usage?
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Ron Hitchens
Craig posted this originally on my behalf, so let me clarify now that I've also registered.

It's very simple.  We want to trap some URL paths to be served from the local filesystem, but not everything.  The Ratpack app sits in front of a backend REST service.  Any paths not recognized by RatPack should be forwarded on.  One of the things we want to intercept is static content like css/js/etc, to handle these at the edge.

This extract from the end of the handlers section of ratpack.groovy should help:

handlers {
     <snip>
        path ("content") { Context c ->
                byMethod {
                        post { insert c.get (IngestHandler) }
                        get { insert c.get (MLPassThruHttpClientHandler) }
                }
        }

        path ("::(css|fonts|images|js).*") {     // This bit doesn't work.  No complaints, but no effect
                files { dir "public" }
        }

        // This is the catch-all handler (works fine) that sends all unmatched requests on to the back end service.
        path ("::.*") { Context c ->
                insert c.get (MLPassThruHttpClientHandler)
        }
}


Placing 'files { dir "public" }' at the end, by itself, works fine but it traps everything.  There are only some paths that we want to match for the local filesystem, I want a final default handler for unrecognized paths.

Does that clarify what we're after?

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Luke Daley
Administrator
Hi,

There's a few problems with this example that would be easier to sort out via real time chat. We just created a public Slack instance.

Would you be open to discussing this there? We can give you better help that way.

You can signup here: http://slack-signup.ratpack.io

Afterwards, you can log in here: http://slack.ratpack.io/ (or via the desktop/mobile Slack client).

FYI - I'm in Australia, and am nearly always around during reasonable hours.

Let me know if that won't work for you and we can try and sort this out async here.
Reply | Threaded
Open this post in threaded view
|

Re: 0.9.18 Equivalent to assets() in Groovy DSL

Ron Hitchens
I'm on the RatPack Slack channel as "ronhitchens"