Skip to content

Instantly share code, notes, and snippets.

@mrserverless
Last active March 14, 2019 12:08
Show Gist options
  • Save mrserverless/280817bd58dff7d8e4b8 to your computer and use it in GitHub Desktop.
Save mrserverless/280817bd58dff7d8e4b8 to your computer and use it in GitHub Desktop.
Dropwizard serving Static Assets on Root URL "/" and APIs on "/api/"
public class ApplicationConfiguration extends Configuration implements AssetsBundleConfiguration {
@Valid
@NotNull
@JsonProperty
private AssetsConfiguration assets;
@Override
public AssetsConfiguration getAssets() {
return assets;
}
}
}
server:
rootPath: '/api/*'
assets:
overrides:
/: public/
@Override
public void initialize( final Bootstrap<ApplicationConfiguration> bootstrap )
{
// root uri maps to static assetes stored in public/ folder. See yml configuration
bootstrap.addBundle( new ConfiguredAssetsBundle( "/assets/", "/", "templates/index.html" ) );
}
@Override
public void run( final ApplicationConfiguration config, final Environment environment ) throws Exception
{
// DW 0.7.0 ONLY: use a different root for APIs to avoid conflict with static asset bundle.
// see https://groups.google.com/forum/#!topic/dropwizard-user/UaVcAYm0VlQ for more details
environment.jersey().setUrlPattern( "/api/*" );
// DW 0.8.0 the above no longer works. See https://groups.google.com/forum/#!msg/dropwizard-user/a_jNCLE7oXM/J4B-R_FlYcEJ
// confight 'rootPath' in yml config instead.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment