Skip to content

Commit

Permalink
[Grid] Add Grid Console URL back
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Sep 8, 2020
1 parent c3195c3 commit 5e90074
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions java/server/src/org/openqa/selenium/grid/commands/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,18 @@
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.netty.server.NettyServer;
import org.openqa.selenium.remote.http.Contents;
import org.openqa.selenium.remote.http.HttpClient;
import org.openqa.selenium.remote.http.HttpHandler;
import org.openqa.selenium.remote.http.HttpResponse;
import org.openqa.selenium.remote.http.Routable;
import org.openqa.selenium.remote.http.Route;
import org.openqa.selenium.remote.tracing.Tracer;

Expand All @@ -54,11 +59,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.EVENT_BUS_ROLE;
import static org.openqa.selenium.grid.config.StandardGridRoles.HTTPD_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 Hub extends TemplateGridCommand {
Expand Down Expand Up @@ -140,7 +147,21 @@ protected void execute(Config config) {
.setContent(Contents.utf8String("Router is " + ready));
};

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("/grid/console").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.with(networkOptions.getSpecComplianceChecks()),
Route.prefix("/wd/hub").to(combine(router.with(networkOptions.getSpecComplianceChecks()))),
Route.post("/graphql").to(() -> graphqlHandler),
Expand Down

0 comments on commit 5e90074

Please sign in to comment.