Skip to content

Commit

Permalink
Support for serving web interface from non-root path (Closes #137)
Browse files Browse the repository at this point in the history
  • Loading branch information
aecio committed Oct 31, 2017
1 parent 13d3cb6 commit 310a5e4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions ache-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
"homepage": ".",
"proxy": "http://localhost:8080"
}
9 changes: 7 additions & 2 deletions ache-dashboard/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,21 @@ 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 (
<Router>
<Router basename={basePath}>
<div>
<Header/>
<div className="container">
<div className="main-content">
<Route exact path="/" component={StartCrawl}/>
<Route exact path="/monitoring" component={MetricsMonitor}/>
<Route exact path="/search" component={Search}/>

</div>
</div>
</div>
Expand Down
13 changes: 12 additions & 1 deletion docs/rest-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand All @@ -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
-------------

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/focusedCrawler/rest/RestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -57,4 +60,8 @@ public String getBasicPassword() {
return basicPassword;
}

public String getBasePath() {
return basePath;
}

}
3 changes: 1 addition & 2 deletions src/main/java/focusedCrawler/rest/RestServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public class StaticFileHandlerFilter implements Filter {

private StaticFilesConfiguration staticFilesHandler;
private Set<String> indexHtmlPaths;
private String basePath;

public StaticFileHandlerFilter(List<String> indexHtmlPaths) {
public StaticFileHandlerFilter(List<String> indexHtmlPaths, String basePath) {
this.basePath = basePath;
this.staticFilesHandler = new StaticFilesConfiguration();
this.staticFilesHandler.configure("/public");
this.indexHtmlPaths = new HashSet<>(indexHtmlPaths);
Expand All @@ -48,6 +50,10 @@ private void renderIndexHtml(Request request, Response response) {
String meta = String.format("<meta name=\"authorization\" content=\"%s\">", authHeader);
indexHtml = indexHtml.replaceFirst("<head>", "<head>" + meta);
}
if(basePath != null && !basePath.isEmpty()) {
String meta = String.format("<meta name=\"base_path\" content=\"%s\">", basePath);
indexHtml = indexHtml.replaceFirst("<head>", "<head>" + meta);
}
writeResponse(request, response, indexHtml);
}

Expand Down

0 comments on commit 310a5e4

Please sign in to comment.