Last active
March 14, 2019 12:08
-
-
Save mrserverless/280817bd58dff7d8e4b8 to your computer and use it in GitHub Desktop.
Dropwizard serving Static Assets on Root URL "/" and APIs on "/api/"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationConfiguration extends Configuration implements AssetsBundleConfiguration { | |
@Valid | |
@NotNull | |
@JsonProperty | |
private AssetsConfiguration assets; | |
@Override | |
public AssetsConfiguration getAssets() { | |
return assets; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server: | |
rootPath: '/api/*' | |
assets: | |
overrides: | |
/: public/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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