Search in sources :

Example 1 with CorsSupport

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();
}
Also used : Config(io.helidon.config.Config) CrossOriginConfig(io.helidon.webserver.cors.CrossOriginConfig) LogConfig(io.helidon.common.LogConfig) CorsSupport(io.helidon.webserver.cors.CorsSupport)

Aggregations

LogConfig (io.helidon.common.LogConfig)1 Config (io.helidon.config.Config)1 CorsSupport (io.helidon.webserver.cors.CorsSupport)1 CrossOriginConfig (io.helidon.webserver.cors.CrossOriginConfig)1