A bundle that provides first class support for [CORS] (https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) in Dropwizard applications.
<dependency>
<groupId>com.github.isaacasensio.dropwizard</groupId>
<artifactId>dropwizard-cors</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
Add a CorsBundle
to your Application class.
@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
// ...
bootstrap.addBundle(new CorsBundle());
}
Implement CorsBundleConfiguration
in your Configuration class.
public class MyConfiguration extends Configuration implements CorsBundleConfiguration{
@Valid
@NotNull
private CorsConfiguration corsConfiguration = new CorsConfiguration();
@JsonProperty("corsConfiguration")
@Override
public CorsConfiguration getCorsConfiguration() {
return corsConfiguration;
}
@JsonProperty("corsConfiguration")
public void setCorsConfiguration(CorsConfiguration corsConfiguration) {
this.corsConfiguration = corsConfiguration;
}
}
For configuring the CORS bundle, there is a CorsConfiguration
:
corsConfiguration:
# Optional: Supported source origins
allowedOrigins: *
# Optional: Supported headers
allowedHeaders: X-Requested-With,Content-Type,Accept,Origin
# Optional: Supported methods
allowedMethods: OPTIONS,GET,PUT,POST,DELETE,HEAD,PATCH
# Optional: Indicates that this preflight response is good for 30 minutes, after which a new preflight request must be issued.
preflightMaxAge: 1800
# Optional: URL mapping where CORS filter will be applied
urlMapping: /*