From b05bf0f9b456875e7601c9fab345daa1b639cd84 Mon Sep 17 00:00:00 2001 From: Alex Bogdanovski Date: Wed, 6 Dec 2023 15:53:17 +0200 Subject: [PATCH] fixed bug preventing external scripts config from being loaded via ENV variable --- src/main/java/com/erudika/scoold/ScooldConfig.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/erudika/scoold/ScooldConfig.java b/src/main/java/com/erudika/scoold/ScooldConfig.java index c5931cbe..85a7f092 100644 --- a/src/main/java/com/erudika/scoold/ScooldConfig.java +++ b/src/main/java/com/erudika/scoold/ScooldConfig.java @@ -24,10 +24,10 @@ import static com.erudika.scoold.ScooldServer.SIGNINLINK; import static com.erudika.scoold.ScooldServer.SIGNOUTLINK; import com.typesafe.config.ConfigObject; -import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import javax.inject.Named; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; @@ -2581,13 +2581,17 @@ public String externalStyles() { description = "A map of external JS scripts. These will be loaded after the main JS script. For example: " + "`scoold.external_scripts.script1 = \"alert('Hi')\"`") public Map externalScripts() { + String prefix = "scoold_external_scripts_"; + Map ext = new LinkedHashMap<>(System.getenv().keySet().stream(). + filter(k -> k.startsWith(prefix)).collect(Collectors. + toMap(mk -> StringUtils.removeStart(mk, prefix), mv -> System.getenv(mv)))); if (getConfig().hasPath("external_scripts")) { ConfigObject extScripts = getConfig().getObject("external_scripts"); if (extScripts != null && !extScripts.isEmpty()) { - return new LinkedHashMap<>(extScripts.unwrapped()); + ext.putAll(extScripts.unwrapped()); } } - return Collections.emptyMap(); + return ext; } @Documented(position = 2410,