Created
April 9, 2016 22:43
-
-
Save aweiland/3406db0ae70e043d67a3bc09dc195e81 to your computer and use it in GitHub Desktop.
CORS in Dropwizard
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
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, "/*"); | |
} |
Also works with Dropwizard 2.1.1. Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works with Dropwizard 1.3.2