Skip to content

Commit

Permalink
Make sure console shortcuts use https when http is disabled
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
(cherry picked from commit 3501531)
  • Loading branch information
phillip-kruger authored and gsmet committed Jan 28, 2025
1 parent c08100c commit 25a7f53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,20 @@ public void run() {

public static void openBrowser(HttpRootPathBuildItem rp, NonApplicationRootPathBuildItem np, String path, String host,
String port) {
IdeProcessor.openBrowser(rp, np, "http", path, host, port);
}

public static void openBrowser(HttpRootPathBuildItem rp, NonApplicationRootPathBuildItem np, String protocol, String path,
String host,
String port) {
if (path.startsWith("/q")) {
path = np.resolvePath(path.substring(3));
} else {
path = rp.resolvePath(path.substring(1));
}

StringBuilder sb = new StringBuilder("http://");
StringBuilder sb = new StringBuilder(protocol);
sb.append("://");
sb.append(host);
sb.append(":");
sb.append(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,21 @@ void setupConsole(HttpRootPathBuildItem rp, NonApplicationRootPathBuildItem np,
}
Config c = ConfigProvider.getConfig();
String host = c.getOptionalValue("quarkus.http.host", String.class).orElse("localhost");
String port = c.getOptionalValue("quarkus.http.port", String.class).orElse("8080");
boolean isInsecureDisabled = c.getOptionalValue("quarkus.http.insecure-requests", String.class)
.map("disabled"::equals)
.orElse(false);

String port = isInsecureDisabled
? c.getOptionalValue("quarkus.http.ssl-port", String.class).orElse("8443")
: c.getOptionalValue("quarkus.http.port", String.class).orElse("8080");

String protocol = isInsecureDisabled ? "https" : "http";

context.reset(
new ConsoleCommand('w', "Open the application in a browser", null, () -> openBrowser(rp, np, "/", host, port)),
new ConsoleCommand('w', "Open the application in a browser", null,
() -> openBrowser(rp, np, protocol, "/", host, port)),
new ConsoleCommand('d', "Open the Dev UI in a browser", null,
() -> openBrowser(rp, np, "/q/dev-ui", host, port)));
() -> openBrowser(rp, np, protocol, "/q/dev-ui", host, port)));
}

@BuildStep(onlyIf = IsDevelopment.class)
Expand Down

0 comments on commit 25a7f53

Please sign in to comment.