From 16fa708f771a0d3ab68c90a8195cb8831d882116 Mon Sep 17 00:00:00 2001 From: Phillip Kruger Date: Mon, 29 May 2023 22:01:00 +1000 Subject: [PATCH] Add DevConsoleCORSFilter to Dev UI JsonRPC WebSocket Signed-off-by: Phillip Kruger --- .../console => devui/deployment}/DevUIConfig.java | 2 +- .../quarkus/devui/deployment/DevUIProcessor.java | 14 ++++++++++++-- .../devmode/console/DevConsoleProcessor.java | 15 +++++++++------ 3 files changed, 22 insertions(+), 9 deletions(-) rename extensions/vertx-http/deployment/src/main/java/io/quarkus/{vertx/http/deployment/devmode/console => devui/deployment}/DevUIConfig.java (91%) diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevUIConfig.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIConfig.java similarity index 91% rename from extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevUIConfig.java rename to extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIConfig.java index 828db66ef474c5..9b9415a33688d7 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevUIConfig.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIConfig.java @@ -1,4 +1,4 @@ -package io.quarkus.vertx.http.deployment.devmode.console; +package io.quarkus.devui.deployment; import io.quarkus.runtime.annotations.ConfigGroup; import io.quarkus.runtime.annotations.ConfigItem; diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIProcessor.java index f57d61b6f898b4..2b2da74494bd51 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/devui/deployment/DevUIProcessor.java @@ -68,6 +68,7 @@ import io.quarkus.vertx.http.deployment.webjar.WebJarBuildItem; import io.quarkus.vertx.http.deployment.webjar.WebJarResourcesFilter; import io.quarkus.vertx.http.deployment.webjar.WebJarResultsBuildItem; +import io.quarkus.vertx.http.runtime.devmode.DevConsoleCORSFilter; import io.smallrye.common.annotation.Blocking; import io.smallrye.common.annotation.NonBlocking; import io.smallrye.mutiny.Multi; @@ -120,6 +121,7 @@ public class DevUIProcessor { @BuildStep(onlyIf = IsDevelopment.class) @Record(ExecutionTime.STATIC_INIT) void registerDevUiHandlers( + DevUIConfig devUIConfig, MvnpmBuildItem mvnpmBuildItem, List devUIRoutesBuildItems, List staticContentBuildItems, @@ -133,6 +135,14 @@ void registerDevUiHandlers( return; } + if (devUIConfig.cors.enabled) { + routeProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() + //.orderedRoute(DEVUI + SLASH_ALL, -1 * FilterBuildItem.CORS) + .route(DEVUI + SLASH_ALL) + .handler(new DevConsoleCORSFilter()) + .build()); + } + // Websocket for JsonRPC comms routeProducer.produce( nonApplicationRootPathBuildItem @@ -155,8 +165,8 @@ void registerDevUiHandlers( .route(route) .handler(uihandler); - if (route.endsWith(DEVUI)) { - builder = builder.displayOnNotFoundPage("Dev UI 2.0"); + if (route.endsWith(DEVUI + SLASH)) { + builder = builder.displayOnNotFoundPage("Dev UI (v2)"); routeProducer.produce(builder.build()); } diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java index ef12ca50856a99..24149fc1e605d1 100644 --- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java +++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/DevConsoleProcessor.java @@ -65,6 +65,7 @@ import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem; import io.quarkus.devconsole.spi.DevConsoleTemplateInfoBuildItem; import io.quarkus.devconsole.spi.DevConsoleWebjarBuildItem; +import io.quarkus.devui.deployment.DevUIConfig; import io.quarkus.maven.dependency.ArtifactKey; import io.quarkus.maven.dependency.GACT; import io.quarkus.netty.runtime.virtual.VirtualChannel; @@ -477,12 +478,6 @@ public void setupDevConsoleRoutes( // if the handler is a proxy, then that means it's been produced by a recorder and therefore belongs in the regular runtime Vert.x instance // otherwise this is handled in the setupDeploymentSideHandling method if (!i.isDeploymentSide()) { - if (devUIConfig.cors.enabled) { - routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() - .route("dev-v1/*") - .handler(new DevConsoleCORSFilter()) - .build()); - } NonApplicationRootPathBuildItem.Builder builder = nonApplicationRootPathBuildItem.routeBuilder() .routeFunction( "dev-v1/" + groupAndArtifact.getKey() + "." + groupAndArtifact.getValue() + "/" + i.getPath(), @@ -496,6 +491,14 @@ public void setupDevConsoleRoutes( } } + if (devUIConfig.cors.enabled) { + routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder() + //.orderedRoute("dev-v1/*", -1 * FilterBuildItem.CORS) + .route("dev-v1/*") + .handler(new DevConsoleCORSFilter()) + .build()); + } + DevConsoleManager.registerHandler(new DevConsoleHttpHandler()); //must be last so the above routes have precedence routeBuildItemBuildProducer.produce(nonApplicationRootPathBuildItem.routeBuilder()