how to do the welcome-file mapping for public/ static file hosting

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

how to do the welcome-file mapping for public/ static file hosting

Paul Hammant
Code:

    ratpack {
        handlers {
            get("results.json") {
                render  JsonOutput.prettyPrint(JsonOutput.toJson(results))
            }
            fileSystem "public", { f -> f.files() }
        }
    }

Inside the fileSystem closure, is there a way of mapping "/" to "/index.html" making it the equivalent to the servlet spec's well known "welcome file"?
Reply | Threaded
Open this post in threaded view
|

Re: how to do the welcome-file mapping for public/ static file hosting

Luke Daley
Administrator
Hi Paul,

You want:

```
    ratpack {
        handlers {
            get("results.json") {
                render  JsonOutput.prettyPrint(JsonOutput.toJson(results))
            }
            files {
                dir "public"
                indexFiles "index.html"
            }
        }
    }
```

See: https://ratpack.io/manual/current/api/ratpack/groovy/handling/GroovyChain.html#files-groovy.lang.Closure-
Reply | Threaded
Open this post in threaded view
|

Re: how to do the welcome-file mapping for public/ static file hosting

Paul Hammant
Thanks that great, I've made a change based on that.

I googled for it within your documentation - https://www.google.com/search?q=indexFiles+site%3Aratpack.io - but it only finds API docs, buy the way.