From 2656fc0b726df9a398f7cc1ef058e5cb0bc44045 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Thu, 9 Nov 2023 16:40:35 +0200 Subject: [PATCH] Allow to set an "root_address" in application.yml. This is used to declare the address of this server, when using proxy. --- .../openaire/pdf_aggregation_statistics/util/UriBuilder.java | 5 ++++- src/main/resources/application.yml | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/openaire/pdf_aggregation_statistics/util/UriBuilder.java b/src/main/java/eu/openaire/pdf_aggregation_statistics/util/UriBuilder.java index fd7bb17..3cdd698 100644 --- a/src/main/java/eu/openaire/pdf_aggregation_statistics/util/UriBuilder.java +++ b/src/main/java/eu/openaire/pdf_aggregation_statistics/util/UriBuilder.java @@ -31,7 +31,10 @@ public class UriBuilder { baseUrl += sslEnabled.equals("true") ? "s" : ""; baseUrl += "://"; - if ( (ip = getPublicIP()) == null ) + String defined_address = environment.getProperty("server.root_address"); + if ( (defined_address != null) && !defined_address.isEmpty() ) + ip = defined_address; + else if ( (ip = getPublicIP()) == null ) ip = InetAddress.getLoopbackAddress().getHostAddress(); // Non-null. baseUrl += ip + ":" + webServerAppCtxt.getWebServer().getPort(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 681353b..d169130 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,5 +1,7 @@ server: port: 1882 + # Just a custom address to be shown to the logs and allow for easier testing, when using proxy. This is not the setting to bind the server to this address. + root_address: servlet: context-path: /api shutdown: graceful