Skip to content

Instantly share code, notes, and snippets.

@Querela
Forked from aweiland/Application.Java
Created September 14, 2022 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Querela/e33e58bd25eedfe55def03fa166137aa to your computer and use it in GitHub Desktop.
Save Querela/e33e58bd25eedfe55def03fa166137aa to your computer and use it in GitHub Desktop.
CORS in Dropwizard
private void configureCors(Environment environment) {
final FilterRegistration.Dynamic cors =
environment.servlets().addFilter("CORS", CrossOriginFilter.class);
// Configure CORS parameters
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "X-Requested-With,Content-Type,Accept,Origin,Authorization");
cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "OPTIONS,GET,PUT,POST,DELETE,HEAD");
cors.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, "true");
// Add URL mapping
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment