public class AssetHandler extends Object implements Route.Handler
Asset
contract.
It has built-in support for static-static as well as SPAs (single page applications).Constructor and Description |
---|
AssetHandler(AssetSource... sources)
Creates a new asset handler.
|
AssetHandler(String fallback,
AssetSource... sources)
Creates a new asset handler that fallback to the given fallback asset when the asset
is not found.
|
Modifier and Type | Method and Description |
---|---|
Object |
apply(Context ctx)
Execute application code.
|
AssetHandler |
setETag(boolean etag)
Turn on/off e-tag support.
|
AssetHandler |
setLastModified(boolean lastModified)
Turn on/off handling of
If-Modified-Since header. |
AssetHandler |
setMaxAge(Duration maxAge)
Set cache-control header with the given max-age value.
|
AssetHandler |
setMaxAge(long maxAge)
Set cache-control header with the given max-age value.
|
void |
setRoute(Route route)
Allows a handler to listen for route metadata.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
then
public AssetHandler(@Nonnull String fallback, AssetSource... sources)
404
its fallback to the given asset.
{
assets("/?*", new AssetHandler("index.html", AssetSource.create(Paths.get("...")));
}
The fallback option makes the asset handler to work like a SPA (Single-Application-Page).fallback
- Fallback asset.sources
- Asset sources.public AssetHandler(AssetSource... sources)
sources
- Asset sources.@Nonnull public Object apply(@Nonnull Context ctx) throws Exception
Route.Handler
apply
in interface Route.Handler
ctx
- Web context.Exception
- If something goes wrong.public AssetHandler setETag(boolean etag)
etag
- True for turning on.public AssetHandler setLastModified(boolean lastModified)
If-Modified-Since
header.lastModified
- True for turning on. Default is: true.public AssetHandler setMaxAge(long maxAge)
maxAge
- Max-age value in seconds.public AssetHandler setMaxAge(Duration maxAge)
maxAge
- Max-age value in seconds.public void setRoute(Route route)
Route.Aware
setRoute
in interface Route.Aware
route
- Route metadata.Copyright © 2020. All rights reserved.