Add settings toggle "apiDocumentationEnabled" which is false by default.

API documentation support seems to take a lot of extra memory,
so this is disabled by default for router-based nodes.
This commit is contained in:
catbref 2019-11-14 11:33:08 +00:00
parent 06794ab36c
commit 238487ea98
2 changed files with 16 additions and 9 deletions

View File

@ -99,16 +99,18 @@ public class ApiService {
apiServlet.setInitOrder(1); apiServlet.setInitOrder(1);
context.addServlet(apiServlet, "/*"); context.addServlet(apiServlet, "/*");
// Swagger-UI static content if (Settings.getInstance().isApiDocumentationEnabled()) {
ClassLoader loader = this.getClass().getClassLoader(); // Swagger-UI static content
ServletHolder swaggerUIServlet = new ServletHolder("static-swagger-ui", DefaultServlet.class); ClassLoader loader = this.getClass().getClassLoader();
swaggerUIServlet.setInitParameter("resourceBase", loader.getResource("resources/swagger-ui/").toString()); ServletHolder swaggerUIServlet = new ServletHolder("static-swagger-ui", DefaultServlet.class);
swaggerUIServlet.setInitParameter("dirAllowed", "true"); swaggerUIServlet.setInitParameter("resourceBase", loader.getResource("resources/swagger-ui/").toString());
swaggerUIServlet.setInitParameter("pathInfoOnly", "true"); swaggerUIServlet.setInitParameter("dirAllowed", "true");
context.addServlet(swaggerUIServlet, "/api-documentation/*"); swaggerUIServlet.setInitParameter("pathInfoOnly", "true");
context.addServlet(swaggerUIServlet, "/api-documentation/*");
rewriteHandler.addRule(new RedirectPatternRule("", "/api-documentation/")); // redirect to Swagger UI start page rewriteHandler.addRule(new RedirectPatternRule("", "/api-documentation/")); // redirect to Swagger UI start page
rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/")); // redirect to Swagger UI start page rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/")); // redirect to Swagger UI start page
}
// Start server // Start server
this.server.start(); this.server.start();

View File

@ -61,6 +61,7 @@ public class Settings {
}; };
private Boolean apiRestricted; private Boolean apiRestricted;
private boolean apiLoggingEnabled = false; private boolean apiLoggingEnabled = false;
private boolean apiDocumentationEnabled = false;
// Specific to this node // Specific to this node
private boolean wipeUnconfirmedOnStart = false; private boolean wipeUnconfirmedOnStart = false;
@ -286,6 +287,10 @@ public class Settings {
return this.apiLoggingEnabled; return this.apiLoggingEnabled;
} }
public boolean isApiDocumentationEnabled() {
return this.apiDocumentationEnabled;
}
public boolean getWipeUnconfirmedOnStart() { public boolean getWipeUnconfirmedOnStart() {
return this.wipeUnconfirmedOnStart; return this.wipeUnconfirmedOnStart;
} }