Skip to content
This repository has been archived by the owner. It is now read-only.

palantir/dropwizard-index-page

develop
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Circle CI Download

Dropwizard Index Page

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

Usage

  1. 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>"
    }
    
  2. Ensure the base tag in your index.html page is set using mustache:

    <base href="{{baseUrl}}">
    
  3. 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;
        }
    }
    
  4. 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/*"));`
        }
    }
    

Configuration

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.

Setting up the project with an IDE

with Eclipse, import the project and run:

    ./gradlew eclipse

with IntelliJ, import the project and run:

    ./gradlew idea

Contributing

Before working on the code, if you plan to contribute changes, please read the CONTRIBUTING document.

License

This project is made available under the Apache 2.0 License.