diff --git a/src/main/java/stirling/software/SPDF/SPdfApplication.java b/src/main/java/stirling/software/SPDF/SPdfApplication.java index d72d02fb..fcbf2ceb 100644 --- a/src/main/java/stirling/software/SPDF/SPdfApplication.java +++ b/src/main/java/stirling/software/SPDF/SPdfApplication.java @@ -7,6 +7,7 @@ import java.nio.file.Paths; import java.util.Collections; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.core.env.Environment; @@ -17,7 +18,6 @@ import io.github.pixee.security.SystemCommand; import jakarta.annotation.PostConstruct; import stirling.software.SPDF.config.ConfigInitializer; -import stirling.software.SPDF.utils.GeneralUtils; @SpringBootApplication @EnableScheduling @@ -27,6 +27,13 @@ public class SPdfApplication { @Autowired private Environment env; + private static String serverPortStatic; + + @Value("${server.port:8080}") + public void setServerPortStatic(String port) { + SPdfApplication.serverPortStatic = port; + } + @PostConstruct public void init() { // Check if the BROWSER_OPEN environment variable is set to true @@ -35,7 +42,7 @@ public class SPdfApplication { if (browserOpen) { try { - String url = "http://localhost:" + getPort(); + String url = "http://localhost:" + getNonStaticPort(); String os = System.getProperty("os.name").toLowerCase(); Runtime rt = Runtime.getRuntime(); @@ -80,15 +87,15 @@ public class SPdfApplication { private static void printStartupLogs() { logger.info("Stirling-PDF Started."); - String url = "http://localhost:" + getPort(); + String url = "http://localhost:" + getStaticPort(); logger.info("Navigate to {}", url); } - public static String getPort() { - String port = System.getProperty("local.server.port"); - if (port == null || port.isEmpty()) { - port = "8080"; - } - return port; + public static String getStaticPort() { + return serverPortStatic; + } + + public String getNonStaticPort() { + return serverPortStatic; } } diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java index 02c37e5c..c773c976 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/ApiDocService.java @@ -36,7 +36,7 @@ public class ApiDocService { private String getApiDocsUrl() { String contextPath = servletContext.getContextPath(); - String port = SPdfApplication.getPort(); + String port = SPdfApplication.getStaticPort(); return "http://localhost:" + port + contextPath + "/v1/api-docs"; } diff --git a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java index c327cdd8..515dd4fe 100644 --- a/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java +++ b/src/main/java/stirling/software/SPDF/controller/api/pipeline/PipelineProcessor.java @@ -64,7 +64,7 @@ public class PipelineProcessor { private String getBaseUrl() { String contextPath = servletContext.getContextPath(); - String port = SPdfApplication.getPort(); + String port = SPdfApplication.getStaticPort(); return "http://localhost:" + port + contextPath + "/"; }