Skip to content

Commit

Permalink
Expose the console for the standalone server
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Sep 7, 2020
1 parent 17ea314 commit d7b8d8b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions java/server/src/org/openqa/selenium/grid/commands/Standalone.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions javascript/grid-ui/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ copy_to_bin(
srcs = glob(
[
"public/*",
"public/css/*",
"src/**/*",
],
) + [
Expand Down

0 comments on commit d7b8d8b

Please sign in to comment.