如何修复夸克反应端点中的"Failed to execute OPTIONS"?



我正在使用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

我试图在应用程序属性中添加以下内容,但没有成功:

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

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

这似乎是一个 CORS 问题。你试过这个吗?

quarkus.http.cors = true

最新更新