From 5615b376271dad04b02482caed8c713aaf065ee9 Mon Sep 17 00:00:00 2001 From: Dario Ghunney Ware Date: Fri, 13 Dec 2024 16:39:21 +0000 Subject: [PATCH] #2270 configuring host --- .../config/security/database/DatabaseConfig.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java index 78f116dbf83..dac6e310db5 100644 --- a/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java +++ b/src/main/java/stirling/software/SPDF/config/security/database/DatabaseConfig.java @@ -15,6 +15,8 @@ @Configuration public class DatabaseConfig { + public static final String DOCKER_HOST = "://db:"; + public static final String LOCALHOST = "://localhost:"; private final ApplicationProperties applicationProperties; public DatabaseConfig(@Autowired ApplicationProperties applicationProperties) { @@ -27,16 +29,20 @@ public Connection connection() throws SQLException { applicationProperties.getSystem().getDatasource(); DataSourceBuilder dataSourceBuilder = DataSourceBuilder.create(); - dataSourceBuilder.driverClassName("org.postgresql.Driver"); - // todo: revert back to -> - // dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver())); - dataSourceBuilder.url(datasource.getUrl()); + dataSourceBuilder.driverClassName(getDriverClassName(datasource.getDriver())); + dataSourceBuilder.url(getUrlForProfile(datasource)); dataSourceBuilder.username(datasource.getUsername()); dataSourceBuilder.password(datasource.getPassword()); return dataSourceBuilder.build().getConnection(); } + private String getUrlForProfile(ApplicationProperties.Datasource datasource) { + return applicationProperties.getSystem().getProfilesActive().equals("default") + ? datasource.getUrl().replace(DOCKER_HOST, LOCALHOST) + : datasource.getUrl(); + } + private String getDriverClassName(ApplicationProperties.Driver driverName) { switch (driverName) { case ORACLE -> {