-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only set
quarkus.http.host
as a default if not available
(cherry picked from commit 917178f)
- Loading branch information
Showing
2 changed files
with
27 additions
and
66 deletions.
There are no files selected for viewing
65 changes: 0 additions & 65 deletions
65
.../vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/HttpHostConfigSource.java
This file was deleted.
Oops, something went wrong.
28 changes: 27 additions & 1 deletion
28
...ns/vertx-http/runtime/src/main/java/io/quarkus/vertx/http/runtime/VertxConfigBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |