A bundle that serves the index page for a single page application. It covers the following areas:
- Serves the index page for a list of url patterns specified during the bundle creation.
- Templates the index page with the correct base tag value, the context path of your application.
- Add disable caching header when serving the index page.
cache-control: no-cache, no-store, max-age=0, must-revalidate
-
Add the
com.palantir.indexpage:dropwizard-index-page:<VERSION>dependency to your project's build.gradle file. The most recent version number can be found by looking at the Releases Page. The dependencies section should look something like this:dependencies { // ... unrelated dependencies omitted ... compile "com.palantir.indexpage:dropwizard-index-page:<VERSION>" } -
Ensure the base tag in your
index.htmlpage is set using mustache:<base href="{{baseUrl}}"> -
Have your configuration implement
IndexPageConfigurable:public final class ExampleApplicationConfiguration extends Configuration implements IndexPageConfigurable { private final String indexPagePath; @JsonCreator ExampleConfig(@JsonProperty("indexPagePath") Optional<String> indexPagePath) { this.indexPagePath = indexPagePath.or("service/web/index.html"); } @Override public String getIndexPagePath() { return this.indexPagePath; } } -
Add the bundle to your application:
public final class ExampleApplication extends Application<ExampleConfiguration> { @Override public void initialize(Bootstrap<ExampleConfiguration> bootstrap) { bootstrap.addBundle(new IndexPageBundle(ImmutableSet.of("/views/*"));` } }
The default index page path is service/web/index.html and you can override the path via the IndexPageConfigurable interface.
NOTE: The path for the index page can be either the file sytem path or the classpath and the file system path takes precedence over the classpath if the file exists in both paths.
with Eclipse, import the project and run:
./gradlew eclipse
with IntelliJ, import the project and run:
./gradlew idea
Before working on the code, if you plan to contribute changes, please read the CONTRIBUTING document.
This project is made available under the Apache 2.0 License.