diff --git a/java/server/src/org/openqa/selenium/grid/commands/Standalone.java b/java/server/src/org/openqa/selenium/grid/commands/Standalone.java index 5f7eccb56aced..ecc1329570a21 100644 --- a/java/server/src/org/openqa/selenium/grid/commands/Standalone.java +++ b/java/server/src/org/openqa/selenium/grid/commands/Standalone.java @@ -40,8 +40,12 @@ import org.openqa.selenium.grid.server.Server; import org.openqa.selenium.grid.sessionmap.SessionMap; import org.openqa.selenium.grid.sessionmap.local.LocalSessionMap; +import org.openqa.selenium.grid.web.ClassPathResource; import org.openqa.selenium.grid.web.CombinedHandler; +import org.openqa.selenium.grid.web.NoHandler; +import org.openqa.selenium.grid.web.ResourceHandler; import org.openqa.selenium.grid.web.RoutableHttpClientFactory; +import org.openqa.selenium.json.Json; import org.openqa.selenium.net.NetworkUtils; import org.openqa.selenium.netty.server.NettyServer; import org.openqa.selenium.remote.http.Contents; @@ -52,6 +56,7 @@ import org.openqa.selenium.remote.http.Route; import org.openqa.selenium.remote.tracing.Tracer; +import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; @@ -61,11 +66,13 @@ import java.util.logging.Logger; import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR; +import static java.net.HttpURLConnection.HTTP_MOVED_TEMP; import static java.net.HttpURLConnection.HTTP_OK; import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_ROLE; import static org.openqa.selenium.grid.config.StandardGridRoles.NODE_ROLE; import static org.openqa.selenium.grid.config.StandardGridRoles.ROUTER_ROLE; import static org.openqa.selenium.remote.http.Route.combine; +import static org.openqa.selenium.remote.http.Route.get; @AutoService(CliCommand.class) public class Standalone extends TemplateGridCommand { @@ -152,7 +159,21 @@ protected void execute(Config config) { BaseServerOptions serverOptions = new BaseServerOptions(config); GraphqlHandler graphqlHandler = new GraphqlHandler(distributor, serverOptions.getExternalUri()); + + Routable ui; + URL uiRoot = getClass().getResource("/javascript/grid-ui/build"); + if (uiRoot != null) { + ResourceHandler uiHandler = new ResourceHandler(new ClassPathResource(uiRoot, "javascript/grid-ui/build")); + ui = Route.combine( + get("/").to(() -> req -> new HttpResponse().setStatus(HTTP_MOVED_TEMP).addHeader("Location", "/ui/index.html")), + Route.prefix("/ui/").to(Route.matching(req -> true).to(() -> uiHandler))); + } else { + Json json = new Json(); + ui = Route.matching(req -> false).to(() -> new NoHandler(json)); + } + HttpHandler httpHandler = combine( + ui, router, Route.prefix("/wd/hub").to(combine(router)), Route.post("/graphql").to(() -> graphqlHandler), diff --git a/javascript/grid-ui/BUILD.bazel b/javascript/grid-ui/BUILD.bazel index a2a4feab2414f..02317a3b572f3 100644 --- a/javascript/grid-ui/BUILD.bazel +++ b/javascript/grid-ui/BUILD.bazel @@ -38,6 +38,7 @@ copy_to_bin( srcs = glob( [ "public/*", + "public/css/*", "src/**/*", ], ) + [