如何在quarkus反应性端点中解决“无法执行OPTIONS”?

问题描述 投票:0回答:1

我正在使用Quarkus 0.24.0和以下扩展名开发API:[cdi,reactive-pg-client,rest-client,resteasy,resteasy-jackson,security,vertx]

这是我实施的路线之一:

@Path("/users")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class UsersResource {

    @Inject
    KeycloakUsersService keycloakUsersService;

    @GET
    @RolesAllowed({"ADMIN"})
    public CompletionStage<Response> getUsers(@QueryParam("search") String searchQuery) {
        return keycloakUsersService.getUsers(searchQuery)
                .thenApply(Response::ok)
                .thenApply(Response.ResponseBuilder::build)
                 .exceptionally(throwable -> {
                    logger.error("Wut ?" + throwable.getMessage());
                    return Response.status(500).entity("Something wrong happened while retrieving users from Keycloak : " + throwable.getCause()).build();
                });
    }
}

在我开始使用Angular使用API​​之前,一切都运行顺利。在进行API调用之前,有一个OPTIONS请求,该请求失败:

 Failed executing OPTIONS /users: org.jboss.resteasy.spi.DefaultOptionsMethodException: RESTEASY003655: No resource method found for options, return OK with Allow header

我尝试在application.properties中添加以下内容,但未成功:

quarkus.http.cors.origins=http://localhost:4200,http://localhost:8080
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
quarkus.http.cors.methods=GET, OPTIONS, POST

如何解决OPTIONS请求?有没有办法全局处理OPTIONS请求?

resteasy quarkus
1个回答
0
投票

这似乎是CORS问题。您尝试过吗?

quarkus.http.cors = true
© www.soinside.com 2019 - 2024. All rights reserved.