我已经在我的应用程序类中为我的Dropwizard应用程序启用了CORS选项,如此
/* Configure CORS parameters */
cors.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
/*
* Allow authorization header, needed for authentication required api's
* Note - comma with spaces does not work
*/
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");
/* Add URL mapping */
cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class),
true,
"/*");
如何为尝试在:8080/healthcheck
上请求运行状况检查API的应用启用此功能?
答案 0 :(得分:0)
您需要将cors过滤器添加到管理员上下文中,例如:
FilterRegistration.Dynamic cors = environment.getAdminContext().getServletContext().addFilter("CORS", CrossOriginFilter.class);
或
environment.getAdminContext().addFilter(...)