Skip to content

Commit 2eb1222

Browse files
authored
Honor bind address and host in configuration (helidon-io#3105)
Signed-off-by: Tomas Langer <tomas.langer@oracle.com>
1 parent 345efbf commit 2eb1222

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

examples/microprofile/multiport/src/main/resources/application.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ server:
1919
sockets:
2020
- name: "private"
2121
port: 8081
22-
bind-address: "localhost"
2322
- name: "admin"
2423
port: 8082
24+
# bind address is optional, if not defined, server host will be used)
2525
bind-address: "localhost"
2626

2727
# Metrics and health run on admin port

webserver/webserver/src/main/java/io/helidon/webserver/NettyWebServer.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package io.helidon.webserver;
1818

1919
import java.net.BindException;
20+
import java.net.InetAddress;
2021
import java.net.InetSocketAddress;
2122
import java.net.SocketAddress;
2223
import java.util.HashMap;
@@ -240,9 +241,14 @@ public synchronized Single<WebServer> start() {
240241
// break because one of the previous channels already failed
241242
break;
242243
}
244+
InetAddress bindAddress = socketConfig.bindAddress();
245+
if (bindAddress == null) {
246+
// fall back to the server bind address
247+
bindAddress = configuration.bindAddress();
248+
}
243249

244250
try {
245-
bootstrap.bind(configuration.bindAddress(), port).addListener(channelFuture -> {
251+
bootstrap.bind(bindAddress, port).addListener(channelFuture -> {
246252
if (!channelFuture.isSuccess()) {
247253
LOGGER.info(() -> "Channel '" + name + "' startup failed with message '"
248254
+ channelFuture.cause().getMessage() + "'.");

webserver/webserver/src/main/java/io/helidon/webserver/ServerConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,8 @@ public Builder config(Config config) {
579579

580580
defaultSocketBuilder.config(config);
581581

582+
config.get("host").asString().ifPresent(defaultSocketBuilder::host);
583+
582584
DeprecatedConfig.get(config, "worker-count", "workers")
583585
.asInt()
584586
.ifPresent(this::workersCount);

0 commit comments

Comments
 (0)