user_mda
user_mda

Reputation: 19418

How to enable CORS on Dropwizard healthcheck api?

I have enable CORS option for my Dropwizard application in my application class like this

    /* 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,
                "/*");

How do I enable this for apps trying to request the healthcheck API on :8080/healthcheck?

Upvotes: 0

Views: 331

Answers (1)

Roman Ivanitsky
Roman Ivanitsky

Reputation: 121

You need add cors filter to admin context like:

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

or

environment.getAdminContext().addFilter(...)

Upvotes: 1

Related Questions