From 310a5e486be10d3beee48337f6275a7588660ecc Mon Sep 17 00:00:00 2001 From: Aecio Santos Date: Tue, 31 Oct 2017 19:18:42 -0400 Subject: [PATCH] Support for serving web interface from non-root path (Closes #137) --- ache-dashboard/package.json | 1 + ache-dashboard/src/App.js | 9 +++++++-- docs/rest-api.rst | 13 ++++++++++++- src/main/java/focusedCrawler/rest/RestConfig.java | 7 +++++++ src/main/java/focusedCrawler/rest/RestServer.java | 3 +-- .../rest/StaticFileHandlerFilter.java | 8 +++++++- 6 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ache-dashboard/package.json b/ache-dashboard/package.json index 8820c7ead..cf3945ac7 100644 --- a/ache-dashboard/package.json +++ b/ache-dashboard/package.json @@ -23,5 +23,6 @@ "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" }, + "homepage": ".", "proxy": "http://localhost:8080" } diff --git a/ache-dashboard/src/App.js b/ache-dashboard/src/App.js index b504479b6..c2edc9c99 100644 --- a/ache-dashboard/src/App.js +++ b/ache-dashboard/src/App.js @@ -47,8 +47,14 @@ const Navigation = ({ label, to, activeOnlyWhenExact }) => ( class App extends Component { render() { + let meta = document.getElementsByName("base_path")[0]; + let basePath; + if(meta !== undefined) { + basePath = meta.content; + } + return ( - +
@@ -56,7 +62,6 @@ class App extends Component { -
diff --git a/docs/rest-api.rst b/docs/rest-api.rst index 797d4c9ea..d2ba2de07 100644 --- a/docs/rest-api.rst +++ b/docs/rest-api.rst @@ -14,8 +14,12 @@ The default HTTP settings can be changed using the following lines in the http.host: 127.0.0.1 http.cors.enabled: true + +Server Mode +----------- + Besides using the ``ache startCrawl`` command, ACHE can also be started in server -mode and controlled using the web user interface. +mode and controlled using the web user interface or the REST API. To start ACHE in server mode, you can use:: @@ -30,6 +34,13 @@ where: * ``$CONFIG`` is the path to where ``ache.yml`` is stored and * ``$DATA`` is the path where ACHE is going to store its data. + +If you want to configure a proxy to serve ACHE user interface from a **non-root** +path, you will need to specify the path in ``ache.yml`` file using the following +configuration:: + + http.base_path: /my-new-path + API Endpoints ------------- diff --git a/src/main/java/focusedCrawler/rest/RestConfig.java b/src/main/java/focusedCrawler/rest/RestConfig.java index 0879422a5..570610016 100644 --- a/src/main/java/focusedCrawler/rest/RestConfig.java +++ b/src/main/java/focusedCrawler/rest/RestConfig.java @@ -23,6 +23,9 @@ public class RestConfig { @JsonProperty("http.auth.basic.password") private String basicPassword = null; + @JsonProperty("http.base_path") + private String basePath = null; + public RestConfig() { // required for de-serialization } @@ -57,4 +60,8 @@ public String getBasicPassword() { return basicPassword; } + public String getBasePath() { + return basePath; + } + } diff --git a/src/main/java/focusedCrawler/rest/RestServer.java b/src/main/java/focusedCrawler/rest/RestServer.java index 7df2fc229..1a3b2d0ec 100644 --- a/src/main/java/focusedCrawler/rest/RestServer.java +++ b/src/main/java/focusedCrawler/rest/RestServer.java @@ -34,7 +34,6 @@ public class RestServer { private ElasticsearchProxyResource elasticsearchProxyResource; private RestServer(String dataPath, Configuration config) { - this.restConfig = config.getRestConfig(); this.elasticsearchProxyResource = new ElasticsearchProxyResource(config); this.threadsResource = new ThreadsResource(); @@ -75,7 +74,7 @@ public void start() { "/search", "/monitoring" ); - server.before("/*", new StaticFileHandlerFilter(indexes)); + server.before("/*", new StaticFileHandlerFilter(indexes, restConfig.getBasePath())); /* * Enable HTTP CORS (Cross-origin Resource Sharing) diff --git a/src/main/java/focusedCrawler/rest/StaticFileHandlerFilter.java b/src/main/java/focusedCrawler/rest/StaticFileHandlerFilter.java index 8d297c201..454da6db4 100644 --- a/src/main/java/focusedCrawler/rest/StaticFileHandlerFilter.java +++ b/src/main/java/focusedCrawler/rest/StaticFileHandlerFilter.java @@ -24,8 +24,10 @@ public class StaticFileHandlerFilter implements Filter { private StaticFilesConfiguration staticFilesHandler; private Set indexHtmlPaths; + private String basePath; - public StaticFileHandlerFilter(List indexHtmlPaths) { + public StaticFileHandlerFilter(List indexHtmlPaths, String basePath) { + this.basePath = basePath; this.staticFilesHandler = new StaticFilesConfiguration(); this.staticFilesHandler.configure("/public"); this.indexHtmlPaths = new HashSet<>(indexHtmlPaths); @@ -48,6 +50,10 @@ private void renderIndexHtml(Request request, Response response) { String meta = String.format("", authHeader); indexHtml = indexHtml.replaceFirst("", "" + meta); } + if(basePath != null && !basePath.isEmpty()) { + String meta = String.format("", basePath); + indexHtml = indexHtml.replaceFirst("", "" + meta); + } writeResponse(request, response, indexHtml); }