use of io.helidon.webserver.cors.CorsSupport in project helidon by oracle.
the class Main method corsSupportForGreeting.
private static CorsSupport corsSupportForGreeting(Config config) {
// The default CorsSupport object (obtained using CorsSupport.create()) allows sharing for any HTTP method and with any
// origin. Using CorsSupport.create(Config) with a missing config node yields a default CorsSupport, which might not be
// what you want. This example warns if either expected config node is missing and then continues with the default.
Config restrictiveConfig = config.get("restrictive-cors");
if (!restrictiveConfig.exists()) {
Logger.getLogger(Main.class.getName()).warning("Missing restrictive config; continuing with default CORS support");
}
CorsSupport.Builder corsBuilder = CorsSupport.builder();
// Use possible overrides first.
config.get("cors").ifExists(c -> {
Logger.getLogger(Main.class.getName()).info("Using the override configuration");
corsBuilder.mappedConfig(c);
});
corsBuilder.config(// restricted sharing for PUT, DELETE
restrictiveConfig).addCrossOrigin(// open sharing for other methods
CrossOriginConfig.create()).build();
return corsBuilder.build();
}
Aggregations