如何在Dropwizard healthcheck api上启用CORS?

时间:2017-11-09 18:08:08

标签: cors dropwizard

我已经在我的应用程序类中为我的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的应用启用此功能?

1 个答案:

答案 0 :(得分:0)

您需要将cors过滤器添加到管理员上下文中,例如:

   FilterRegistration.Dynamic cors = environment.getAdminContext().getServletContext().addFilter("CORS", CrossOriginFilter.class);

environment.getAdminContext().addFilter(...)
相关问题