diff --git a/src/main/java/stirling/software/SPDF/SPDFApplication.java b/src/main/java/stirling/software/SPDF/SPDFApplication.java index 5ac9f663e..3cf89a657 100644 --- a/src/main/java/stirling/software/SPDF/SPDFApplication.java +++ b/src/main/java/stirling/software/SPDF/SPDFApplication.java @@ -37,6 +37,7 @@ public class SPDFApplication { private static String serverPortStatic; private static String baseUrlStatic; + private static String contextPathStatic; private final Environment env; private final ApplicationProperties applicationProperties; @@ -45,6 +46,9 @@ public class SPDFApplication { @Value("${baseUrl:http://localhost}") private String baseUrl; + @Value("${server.servlet.context-path:/}") + private String contextPath; + public SPDFApplication( Environment env, ApplicationProperties applicationProperties, @@ -138,7 +142,8 @@ public class SPDFApplication { @PostConstruct public void init() { baseUrlStatic = this.baseUrl; - String url = baseUrl + ":" + getStaticPort(); + contextPathStatic = this.contextPath; + String url = baseUrl + ":" + getStaticPort() + contextPath; if (webBrowser != null && Boolean.parseBoolean(System.getProperty("STIRLING_PDF_DESKTOP_UI", "false"))) { webBrowser.initWebUI(url); @@ -195,7 +200,7 @@ public class SPDFApplication { private static void printStartupLogs() { log.info("Stirling-PDF Started."); - String url = baseUrlStatic + ":" + getStaticPort(); + String url = baseUrlStatic + ":" + getStaticPort() + contextPathStatic; log.info("Navigate to {}", url); } @@ -220,4 +225,8 @@ public class SPDFApplication { public static String getStaticPort() { return serverPortStatic; } + + public static String getStaticContextPath() { + return contextPathStatic; + } } diff --git a/src/main/java/stirling/software/SPDF/config/AppConfig.java b/src/main/java/stirling/software/SPDF/config/AppConfig.java index 58719f1d0..46c580369 100644 --- a/src/main/java/stirling/software/SPDF/config/AppConfig.java +++ b/src/main/java/stirling/software/SPDF/config/AppConfig.java @@ -8,6 +8,7 @@ import java.util.List; import java.util.Properties; import java.util.function.Predicate; +import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; @@ -78,6 +79,11 @@ public class AppConfig { return applicationProperties.getUi().getLanguages(); } + @Bean + public String contextPath(@Value("${server.servlet.context-path}") String contextPath) { + return contextPath; + } + @Bean(name = "navBarText") public String navBarText() { String defaultNavBar = diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index 77a673c04..900e2539a 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -130,7 +130,7 @@ async function getPDFPageCount(file) { try { const arrayBuffer = await file.arrayBuffer(); - pdfjsLib.GlobalWorkerOptions.workerSrc = '/pdfjs-legacy/pdf.worker.mjs'; + pdfjsLib.GlobalWorkerOptions.workerSrc = './pdfjs-legacy/pdf.worker.mjs'; const pdf = await pdfjsLib.getDocument({data: arrayBuffer}).promise; return pdf.numPages; } catch (error) { diff --git a/src/main/resources/static/js/pages/home.js b/src/main/resources/static/js/pages/home.js index 6e72cdece..8565c44a2 100644 --- a/src/main/resources/static/js/pages/home.js +++ b/src/main/resources/static/js/pages/home.js @@ -33,10 +33,11 @@ function setAnalytics(enabled) { } updateFavoriteIcons(); +const contentPath = /*[[${@contextPath}]]*/ ''; const defaultView = localStorage.getItem('defaultView') || 'home'; // Default to "home" if (defaultView === 'home-legacy') { - window.location.href = '/home-legacy'; // Redirect to legacy view + window.location.href = contentPath + 'home-legacy'; // Redirect to legacy view } document.addEventListener('DOMContentLoaded', function () { diff --git a/src/main/resources/templates/fragments/navbar.html b/src/main/resources/templates/fragments/navbar.html index 8720b2f72..06defd47b 100644 --- a/src/main/resources/templates/fragments/navbar.html +++ b/src/main/resources/templates/fragments/navbar.html @@ -24,7 +24,7 @@ border-bottom-width: 1px; border-color: var(--md-nav-color-on-seperator)">
- + icon @@ -265,17 +265,18 @@
- diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 1450c7489..925aefe8e 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -219,7 +219,7 @@ window.analyticsPromptBoolean = /*[[${@analyticsPrompt}]]*/ false; /*]]>*/ - + diff --git a/src/main/resources/templates/merge-pdfs.html b/src/main/resources/templates/merge-pdfs.html index f6ace6d74..d10b65801 100644 --- a/src/main/resources/templates/merge-pdfs.html +++ b/src/main/resources/templates/merge-pdfs.html @@ -52,8 +52,8 @@ const pagesTranslation = document.getElementById('pagesTranslation').innerText; // Get translation for multiple pages