mirror of
https://github.com/Qortal/qortal.git
synced 2025-02-12 18:25:49 +00:00
Show informative page instead of "Forbidden" when user tries to access API documentation when disabled.
This commit is contained in:
parent
9156325ffc
commit
fa1aa1c8b2
@ -108,8 +108,19 @@ public class ApiService {
|
|||||||
swaggerUIServlet.setInitParameter("pathInfoOnly", "true");
|
swaggerUIServlet.setInitParameter("pathInfoOnly", "true");
|
||||||
context.addServlet(swaggerUIServlet, "/api-documentation/*");
|
context.addServlet(swaggerUIServlet, "/api-documentation/*");
|
||||||
|
|
||||||
rewriteHandler.addRule(new RedirectPatternRule("", "/api-documentation/")); // redirect to Swagger UI start page
|
rewriteHandler.addRule(new RedirectPatternRule("", "/api-documentation/")); // redirect empty path to API docs
|
||||||
rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/")); // redirect to Swagger UI start page
|
rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/")); // redirect to add trailing slash if missing
|
||||||
|
} else {
|
||||||
|
// Simple pages that explains that API documentation is disabled
|
||||||
|
ClassLoader loader = this.getClass().getClassLoader();
|
||||||
|
ServletHolder swaggerUIServlet = new ServletHolder("api-docs-disabled", DefaultServlet.class);
|
||||||
|
swaggerUIServlet.setInitParameter("resourceBase", loader.getResource("api-docs-disabled/").toString());
|
||||||
|
swaggerUIServlet.setInitParameter("dirAllowed", "true");
|
||||||
|
swaggerUIServlet.setInitParameter("pathInfoOnly", "true");
|
||||||
|
context.addServlet(swaggerUIServlet, "/api-documentation/*");
|
||||||
|
|
||||||
|
rewriteHandler.addRule(new RedirectPatternRule("", "/api-documentation/")); // redirect empty path to API docs
|
||||||
|
rewriteHandler.addRule(new RedirectPatternRule("/api-documentation", "/api-documentation/")); // redirect to add trailing slash if missing
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
|
13
src/main/resources/api-docs-disabled/index.html
Normal file
13
src/main/resources/api-docs-disabled/index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>API Documentation disabled</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
API documentation pages are currently disabled.
|
||||||
|
<p>
|
||||||
|
To enable, add an entry like this to your <tt>settings.json</tt> file:
|
||||||
|
<p>
|
||||||
|
<code>"apiDocumentationEnabled": true,</code>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user