Skip to content

Commit

Permalink
Add DevConsoleCORSFilter to Dev UI JsonRPC WebSocket
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed May 29, 2023
1 parent 97482f2 commit 16fa708
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -120,6 +121,7 @@ public class DevUIProcessor {
@BuildStep(onlyIf = IsDevelopment.class)
@Record(ExecutionTime.STATIC_INIT)
void registerDevUiHandlers(
DevUIConfig devUIConfig,
MvnpmBuildItem mvnpmBuildItem,
List<DevUIRoutesBuildItem> devUIRoutesBuildItems,
List<StaticContentBuildItem> staticContentBuildItems,
Expand All @@ -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
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
Expand All @@ -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()
Expand Down

0 comments on commit 16fa708

Please sign in to comment.