FileServer files = new FileServer(content).header(CACHE_CONTROL, "public; max-age=60");
// Serve static assets for css, js and image files from the content dir.
StaticAssets assets = new StaticAssets(files).serve("/css", "/js", "/images");
// We use Mustache templates with an .html extension
Templates templates = new Templates(new JMustacheRenderer().fromDir(content).extension("html"));
final Template index = templates.named("index");
// Add content length header when size of content is known
server.add(new ContentLengthHeader())
// Make get and head requests conditional to freshness of client stored representation
.add(new ConditionalGet())
// Add ETag if response has no validation information
.add(new ETag())
// Compress bodies that are not images
.add(new Compressor().compressibleTypes(JAVASCRIPT, CSS, HTML))
.add(assets)
.start(new Application() {
public void handle(Request request, Response response) throws Exception {
response.set(CONTENT_TYPE, HTML);
response.set(LAST_MODIFIED, request.parameter("timestamp"));
response.body(index.render(NO_CONTEXT));
}
});
}