Skip to content

Commit

Permalink
Only set quarkus.http.host as a default if not available
Browse files Browse the repository at this point in the history
(cherry picked from commit 917178f)
  • Loading branch information
radcortez authored and gsmet committed May 10, 2024
1 parent 12a0330 commit 68b7e76
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 66 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
package io.quarkus.vertx.http.runtime;

import io.quarkus.runtime.LaunchMode;
import io.quarkus.runtime.configuration.ConfigBuilder;
import io.smallrye.config.SmallRyeConfigBuilder;

public class VertxConfigBuilder implements ConfigBuilder {
private static final String QUARKUS_HTTP_HOST = "quarkus.http.host";
private static final String ALL_INTERFACES = "0.0.0.0";

@Override
public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) {
return builder.withSources(new HttpHostConfigSource());
// It may have been recorded, so only set if it not available in the defaults
if (builder.getDefaultValues().get(QUARKUS_HTTP_HOST) == null) {
// Sets the default host config value, depending on the launch mode
if (LaunchMode.isRemoteDev()) {
// in remote-dev mode we need to listen on all interfaces
builder.withDefaultValue(QUARKUS_HTTP_HOST, ALL_INTERFACES);
} else {
// 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.
builder.withDefaultValue(QUARKUS_HTTP_HOST,
(LaunchMode.current().isDevOrTest() && !isWSL()) ? "localhost" : ALL_INTERFACES);
}
}
return builder;
}

/**
* @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");
}
}

0 comments on commit 68b7e76

Please sign in to comment.