Skip to content

Commit

Permalink
Print localhost instead of 0.0.0.0 when in dev/test mode under WSL
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaro-skaljic committed May 7, 2024
1 parent ea5c6fd commit 8e383a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,11 @@ public String getValue(String propertyName) {
// In dev-mode we want to only listen on localhost so others on the network cannot connect to the application.
// However, in WSL this would result in the application not being accessible,
// so in that case, we launch it on all interfaces.
return (LaunchMode.current().isDevOrTest() && !isWSL()) ? "localhost" : ALL_INTERFACES;
return (LaunchMode.current().isDevOrTest() && !LaunchMode.isWSL()) ? "localhost" : ALL_INTERFACES;
}
return null;
}

/**
* @return {@code true} if the application is running in a WSL (Windows Subsystem for Linux) environment
*/
private boolean isWSL() {
var sysEnv = System.getenv();
return sysEnv.containsKey("IS_WSL") || sysEnv.containsKey("WSL_DISTRO_NAME");
}

@Override
public String getName() {
return "Quarkus HTTP Host Default Value";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,34 +899,40 @@ private static void setHttpServerTiming(boolean httpDisabled, HttpServerOptions
int socketCount = 0;

if (!httpDisabled && httpServerOptions != null) {
serverListeningMessage.append(String.format(
"http://%s:%s", httpServerOptions.getHost(), actualHttpPort));
serverListeningMessage.append(String.format("http://%s:%s", getHost(httpServerOptions), actualHttpPort));
socketCount++;
}

if (sslConfig != null) {
if (socketCount > 0) {
serverListeningMessage.append(" and ");
}
serverListeningMessage.append(String.format("https://%s:%s", sslConfig.getHost(), actualHttpsPort));
serverListeningMessage.append(String.format("https://%s:%s", getHost(sslConfig), actualHttpsPort));
socketCount++;
}

if (domainSocketOptions != null) {
if (socketCount > 0) {
serverListeningMessage.append(" and ");
}
serverListeningMessage.append(String.format("unix:%s", domainSocketOptions.getHost()));
serverListeningMessage.append(String.format("unix:%s", getHost(domainSocketOptions)));
}
if (managementConfig != null) {
serverListeningMessage.append(
String.format(". Management interface listening on http%s://%s:%s.", managementConfig.isSsl() ? "s" : "",
managementConfig.getHost(), actualManagementPort));
getHost(managementConfig), actualManagementPort));
}

Timing.setHttpServer(serverListeningMessage.toString(), auxiliaryApplication);
}

/**
* @return The host or 'localhost' when started in dev/test mode under WSL.
*/
private static String getHost(HttpServerOptions options) {
return (LaunchMode.current().isDevOrTest() && LaunchMode.isWSL()) ? "localhost" : options.getHost();
}

private static HttpServerOptions createHttpServerOptions(
HttpBuildTimeConfig buildTimeConfig, HttpConfiguration httpConfiguration,
LaunchMode launchMode, List<String> websocketSubProtocols) {
Expand Down

0 comments on commit 8e383a8

Please sign in to comment.