diff --git a/examples/nginx-contextpath/README.md b/examples/nginx-contextpath/README.md index e4a190a..45d5234 100644 --- a/examples/nginx-contextpath/README.md +++ b/examples/nginx-contextpath/README.md @@ -41,10 +41,6 @@ YEAH! You are now using PlantUML behind a simple Nginx reverse proxy. # PlantUML location /plantuml/ { - proxy_set_header HOST $host; - proxy_set_header X-Forwarded-Host $host; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://plantuml-server:8080/plantuml/; } @@ -52,12 +48,31 @@ location /plantuml/ { ``` - `location /plantuml/` to reverse only the context path `/plantuml` -- `proxy_set_header HOST $host` and `proxy_set_header X-Forwarded-Host $host` to replaces local plantuml server ip with FQDN -- `proxy_set_header X-Forwarded-Proto $scheme` to use reverse proxy protocol schema instead of communication schema between reverse proxy and plantuml server - `proxy_pass http://plantuml-server:8080/plantuml/` to set reverse proxy path to plantuml server. Use the docker container name `plantuml-server` instead of ip addresses. Also, use the same context path (`BASE_URL`) as PlantUML, which is configurable as an environment variable in the docker-compose file. +NOTE: `BASE_URL`, `location` and therefore the `proxy_pass` should have the some context path! +If that is not possible it may be possible to solve the problem by using NGINX `sub_filter`: +```nginx +# PlantUML +location /plantuml/ { + sub_filter '' ''; + sub_filter_types text/html; + + proxy_pass http://plantuml-server:8080/; +} +``` + +NOTE: Since [PR#256](https://github.com/plantuml/plantuml-server/pull/256) it is possible to use deep base URLs. +So with e.g. `BASE_URL=foo/bar` the following is possible: +```nginx +# PlantUML +location /foo/bar/ { + proxy_pass http://plantuml-server:8080/foo/bar/; +} +``` + ## Nginx and PlantUML server diff --git a/examples/nginx-contextpath/nginx.conf b/examples/nginx-contextpath/nginx.conf index e5f2852..6406659 100644 --- a/examples/nginx-contextpath/nginx.conf +++ b/examples/nginx-contextpath/nginx.conf @@ -18,10 +18,6 @@ http { # PlantUML location /plantuml/ { - proxy_set_header HOST $host; - proxy_set_header X-Forwarded-Host $host; - proxy_set_header X-Forwarded-Proto $scheme; - proxy_pass http://plantuml-server:8080/plantuml/; } } diff --git a/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java index cd83b63..1444a0b 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/PlantUmlServlet.java @@ -254,17 +254,14 @@ public class PlantUmlServlet extends HttpServlet { // properties request.setAttribute("showSocialButtons", Configuration.get("SHOW_SOCIAL_BUTTONS")); request.setAttribute("showGithubRibbon", Configuration.get("SHOW_GITHUB_RIBBON")); - // URL base - final String contextpath = request.getContextPath(); - request.setAttribute("contextpath", contextpath); // image URLs final boolean hasImg = !text.isEmpty(); request.setAttribute("hasImg", hasImg); - request.setAttribute("imgurl", contextpath + "/png/" + index + encoded); - request.setAttribute("svgurl", contextpath + "/svg/" + index + encoded); - request.setAttribute("pdfurl", contextpath + "/pdf/" + index + encoded); - request.setAttribute("txturl", contextpath + "/txt/" + index + encoded); - request.setAttribute("mapurl", contextpath + "/map/" + index + encoded); + request.setAttribute("imgurl", "png/" + index + encoded); + request.setAttribute("svgurl", "svg/" + index + encoded); + request.setAttribute("pdfurl", "pdf/" + index + encoded); + request.setAttribute("txturl", "txt/" + index + encoded); + request.setAttribute("mapurl", "map/" + index + encoded); // map for diagram source if necessary final boolean hasMap = PlantumlUtils.hasCMapData(text); request.setAttribute("hasMap", hasMap); @@ -312,14 +309,13 @@ public class PlantUmlServlet extends HttpServlet { String encoded, Integer index ) throws IOException { - final String result; + final String path; if (index == null || index < 0) { - result = request.getContextPath() + "/uml/" + encoded; + path = request.getContextPath() + "/uml/" + encoded; } else { - result = request.getContextPath() + "/uml/" + index + "/" + encoded; + path = request.getContextPath() + "/uml/" + index + "/" + encoded; } - - response.sendRedirect(result); + response.sendRedirect(path); } /** diff --git a/src/main/webapp/error.jsp b/src/main/webapp/error.jsp index 8743344..53c9661 100644 --- a/src/main/webapp/error.jsp +++ b/src/main/webapp/error.jsp @@ -1,19 +1,16 @@ <%@ page isErrorPage="true" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %> -<% - String contextpath = request.getContextPath(); -%> - + - - - + + + PlantUMLServer Error diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index ae2d4ad..4da6ec8 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -6,8 +6,6 @@ // properties boolean showSocialButtons = (boolean)request.getAttribute("showSocialButtons"); boolean showGithubRibbon = (boolean)request.getAttribute("showGithubRibbon"); - // URL base - String contextpath = request.getAttribute("contextpath").toString(); // image URLs boolean hasImg = (boolean)request.getAttribute("hasImg"); String imgurl = request.getAttribute("imgurl").toString(); @@ -23,31 +21,17 @@ + - - - - - - + + + + + + PlantUMLServer @@ -64,7 +48,7 @@
<%-- CONTENT --%> -
+

  @@ -73,7 +57,7 @@


You can enter here a previously generated URL:

-
+


@@ -103,33 +87,6 @@

<% } %>
- <%-- FOOTER --%> <%@ include file="footer.jspf" %> diff --git a/src/main/webapp/plantuml.js b/src/main/webapp/plantuml.js new file mode 100644 index 0000000..c85cf51 --- /dev/null +++ b/src/main/webapp/plantuml.js @@ -0,0 +1,58 @@ +/************************* +* PlantUMLServlet script * +**************************/ + +let clipboard_write = false; +let clipboard_read = false; + +function copyToClipboard(fieldid, fielddesc) { + if (clipboard_write) { + navigator.clipboard.writeText(document.getElementById(fieldid).value); + alert(fielddesc + " copied to clipboard"); + } + return false; +} + +function loadCodeMirror() { + document.myCodeMirror = CodeMirror.fromTextArea( + document.getElementById("text"), + { + lineNumbers: true, + extraKeys: {Tab: false, "Shift-Tab": false} + } + ); +} + +function resolvePath(path) { + if (path.startsWith("http")) return path; + if (path.startsWith("/")) return window.location.origin + path; + + if (path.slice(0, 2) == "./") path = path.slice(2); + let base = (document.querySelector('base') || {}).href || window.location.origin; + if (base.slice(-1) == "/") base = base.slice(0, -1); + return base + "/" + path; +} + +window.onload = function() { + loadCodeMirror(); + + // resolve relative path inside url input once + const url = document.getElementById("url"); + url.value = resolvePath(url.value); + + // clipboard check (from PR#250) + // TODO: not supported by Firefox, Safari or WebView Android + // https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility + if (navigator.permissions){ + navigator.permissions.query({ name: "clipboard-write" }).then((result) => { + if (result.state == "granted" || result.state == "prompt") { + clipboard_write = true; + } + }); + navigator.permissions.query({ name: "clipboard-read" }).then((result) => { + if (result.state == "granted" || result.state == "prompt") { + clipboard_read = true; + } + }); + }; +};