'Vert.x : Cors Handling doesn't work with wildcard routing

I'm using CorsHandler to handle the CORS problem, now it's showing errors when mapping with a wildcard, I tried several times to change it to a specific route, but the code doesn't compile then.

Set<String> allowedHeaders = new HashSet<>();
    allowedHeaders.add("x-requested-with");
    allowedHeaders.add("Access-Control-Allow-Origin");
    allowedHeaders.add("origin");
    allowedHeaders.add("Content-Type");
    allowedHeaders.add("accept");
    allowedHeaders.add("withCredentials");

    Set<HttpMethod> allowedMethods = new HashSet<>();
    allowedMethods.add(HttpMethod.GET);
    allowedMethods.add(HttpMethod.POST);
    allowedMethods.add(HttpMethod.DELETE);
    allowedMethods.add(HttpMethod.PATCH);
    allowedMethods.add(HttpMethod.OPTIONS);
    allowedMethods.add(HttpMethod.PUT);

    router
            .route()
            .handler(
                    io.vertx.ext.web.handler.CorsHandler.create("*")
                            .addOrigin("http://localhost:8080")
                            .allowedHeaders(allowedHeaders)
                            .allowedMethods(allowedMethods)
                            .allowCredentials(true));

The CorsHandler works with a specific route in one condition: only if i remove the addOrigin, which results in having a frontend that doesn't detect any CorsHandler.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source