diff --git a/Backend-libXML/main.py b/Backend-libXML/main.py index 4445cab..e4fefe5 100644 --- a/Backend-libXML/main.py +++ b/Backend-libXML/main.py @@ -9,11 +9,11 @@ import Parser app = Flask(__name__) CORS(app) -cors = CORS(app, resource={ - r"/*":{ - "origins":"*" - } -}) +# cors = CORS(app, resource={ +# r"/*":{ +# "origins":"*" +# } +# }) def process_xml(request: request, type: str) -> str: """Function to process diff --git a/Frontend/assets/scripts/tools/mock/datatransfer.js b/Frontend/assets/scripts/tools/mock/datatransfer.js index 34945a2..f1f0811 100644 --- a/Frontend/assets/scripts/tools/mock/datatransfer.js +++ b/Frontend/assets/scripts/tools/mock/datatransfer.js @@ -4,7 +4,7 @@ var json = {}; var jsonIndex = 0; var lastId = 1; var htable_row = 0; -var host = window.location.protocol + "//" + window.location.hostname + ":8097"; +var host = window.location.protocol + "//" + window.location.hostname + "/mock"; var dataModified = false; const addMessageName = 'addMessage'; const loadMessageName = 'changeMessage'; diff --git a/Frontend/assets/scripts/tools/mock/uianimation.js b/Frontend/assets/scripts/tools/mock/uianimation.js index 7340b83..66b6625 100644 --- a/Frontend/assets/scripts/tools/mock/uianimation.js +++ b/Frontend/assets/scripts/tools/mock/uianimation.js @@ -78,7 +78,8 @@ function showHeadersHistory(element){ } async function formatJSON(json) { - const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"; + const backend = "java"; + const address = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/json/formatting"; var init = { body: json, @@ -98,7 +99,8 @@ async function formatJSON(json) { } async function formatXML(xml) { - const address = window.location.protocol + "//" + window.location.hostname + ":" + 8082 + "/prettify"; + const backend = "libxml"; + const address = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/prettify"; var data = { data: xml, process: "", @@ -140,7 +142,7 @@ function showRequestBody(element){ }); break; } - case "application/xml":{ + case "application/xml": { formatXML(historyRequestBody).then(function(result) { if (result.status == "OK") { popupContent.innerText = result.result; diff --git a/Frontend/assets/scripts/tools/scripts.js b/Frontend/assets/scripts/tools/scripts.js index 3532208..729ee8e 100644 --- a/Frontend/assets/scripts/tools/scripts.js +++ b/Frontend/assets/scripts/tools/scripts.js @@ -76,7 +76,7 @@ function clearDataField() { */ function fillDefaultXML(element) { if (element.classList.contains("active")) { - const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086"; + const serverAddress = window.location.protocol + "//" + window.location.hostname; clearDefaultContent(document.getElementById("xmlArea"), "Insert XML here"); fetch(serverAddress + "/assets/samples/sampleXml.xml") .then(response => response.text()) @@ -100,7 +100,7 @@ function fillDefaultXML(element) { * @returns {void} */ function fillDefaultXSD(){ - const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086"; + const serverAddress = window.location.protocol + "//" + window.location.hostname; fetch(serverAddress + "/assets/samples/sampleXSD.xsd") .then( response => response.text() ) .then( (XSDSchema) => { @@ -126,7 +126,7 @@ function fillDefaultXSD(){ * @returns {void} */ function fillDefaultXSLT() { - const serverAddress = window.location.protocol + "//" + window.location.hostname + ":8086"; + const serverAddress = window.location.protocol + "//" + window.location.hostname; fetch(serverAddress + "/assets/samples/XSLTTemplate.xslt") .then( response => response.text() ) .then( (XSTLTemplate) => { @@ -277,9 +277,9 @@ function performRequest(endpoint, checkXML, checkTransform) { var xmlData = document.getElementById(sourceId).innerText.trim(); var transformData = document.getElementById(transformId).innerText.trim(); - var port = 8081; + var backend = "java"; if (getProcessor() == "libxml") { - port = 8082; + backend = "libxml"; } var empty = false; @@ -293,7 +293,7 @@ function performRequest(endpoint, checkXML, checkTransform) { empty = true; } if (!empty) { - restRequest(port, endpoint, xmlData, transformData).then(function (result) { + restRequest(backend, endpoint, xmlData, transformData).then(function (result) { document.getElementById("resultArea").innerText = result.result; highlightSyntax("resultArea"); document.getElementById("procinfo").innerText = ' Computed using ' + result.processor; @@ -333,7 +333,7 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) { const sourceElement = document.getElementById(sourceId); const targetElement = document.getElementById(targetId); const infoElement = document.getElementById("formatinfo"); - const port = 8082; + const backend = "libxml"; var xmlData = sourceElement.innerText.trim(); var empty = false; @@ -344,7 +344,7 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) { } if (!empty) { - restRequest(port, endpoint, xmlData, "").then(function (result) { + restRequest(backend, endpoint, xmlData, "").then(function (result) { if (result.status == "OK") { targetElement.innerText = result.result.trim(); highlightSyntax(targetElement.id); @@ -374,16 +374,15 @@ function performFormatRequest(endpoint, checkXML, sourceId, targetId) { * @function * @name restRequest * @kind function -* @param {any} port of target service +* @param {any} backend target backend * @param {any} endpoint of target service * @param {any} xmlData XML that will be sent * @param {any} transformData data used to transform given XML * @returns {Promise} */ -async function restRequest(port, endpoint, xmlData, transformData) { - const escapeChar = "specialEscapeChar"; +async function restRequest(backend, endpoint, xmlData, transformData) { - const addr = window.location.protocol + "//" + window.location.hostname + ":" + port + "/" + endpoint; + const addr = window.location.protocol + "//" + window.location.hostname + "/" + backend + "/" + endpoint; if (defaultStrings.includes(xmlData)) { xmlData = ""; diff --git a/Frontend/nginx.conf b/Frontend/nginx.conf index e52fbb2..74e93e6 100644 --- a/Frontend/nginx.conf +++ b/Frontend/nginx.conf @@ -12,8 +12,26 @@ server { add_header Cache-Control "private, no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"; } + location /java/ { + proxy_pass http://xmltools-backend:8081/; + proxy_set_header Host $host; + } + + location /libxml/ { + proxy_pass http://xmltools-libxml-backend/; + proxy_set_header Host $host; + } + + location /mock/ { + proxy_pass http://xmltools-mocked-services:8097/; + proxy_set_header Host $host; + proxy_set_header Content-Type $http_content_type; + } + #error_page 404 /404.html; + + # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; diff --git a/Frontend/tools/jsonFormatter.html b/Frontend/tools/jsonFormatter.html index 8081f02..59eee48 100644 --- a/Frontend/tools/jsonFormatter.html +++ b/Frontend/tools/jsonFormatter.html @@ -31,7 +31,7 @@ + onclick="insertDefaultJson()">Insert default JSON
diff --git a/Samples/minimize/minimize.curl b/Samples/minimize/minimize.curl
index 3a74ae5..3a94a93 100644
--- a/Samples/minimize/minimize.curl
+++ b/Samples/minimize/minimize.curl
@@ -1,3 +1,3 @@
-url = "http://localhost:5000/minimize"
+url = "http://localhost/libxml/minimize"
 data = "@minimize.json"
 request = POST
diff --git a/Samples/prettify/prettify.curl b/Samples/prettify/prettify.curl
index a10aa88..fc3ab49 100644
--- a/Samples/prettify/prettify.curl
+++ b/Samples/prettify/prettify.curl
@@ -1,3 +1,3 @@
-url = "http://localhost:5000/prettify"
+url = "http://localhost:5000/libxml/prettify"
 data = "@prettify.json"
 request = POST
diff --git a/Samples/xpath/non-ns.curl b/Samples/xpath/non-ns.curl
index b54c5b6..e6af844 100644
--- a/Samples/xpath/non-ns.curl
+++ b/Samples/xpath/non-ns.curl
@@ -1,4 +1,4 @@
-#url = "localhost:8081/xpath"
-url = "localhost:5000/xpath"
+url = "localhost/java/xpath"
+#url = "localhost/libxml/xpath"
 request = "POST"
 data = "@data.json"
diff --git a/Samples/xpath/ns.curl b/Samples/xpath/ns.curl
index 46c6341..c55e0fe 100644
--- a/Samples/xpath/ns.curl
+++ b/Samples/xpath/ns.curl
@@ -1,4 +1,4 @@
-#url = "localhost:8081/xpath"
-url = "localhost:5000/xpath"
+url = "localhost/java/xpath"
+#url = "localhost/libxml/xpath"
 request = "POST"
 data = "@dataNS.json"
diff --git a/Samples/xsd/xsd.curl b/Samples/xsd/xsd.curl
index 922856c..8de3bdd 100644
--- a/Samples/xsd/xsd.curl
+++ b/Samples/xsd/xsd.curl
@@ -1,4 +1,4 @@
-#url = "http://localhost:8081/xsd"
-url = "http://localhost:5000/xsd"
+url = "localhost/java/xsd"
+#url = "localhost/libxml/xsd"
 data = "@xsd.json"
 request = POST
diff --git a/Samples/xslt/xslt.curl b/Samples/xslt/xslt.curl
index 712c82c..22adc0f 100644
--- a/Samples/xslt/xslt.curl
+++ b/Samples/xslt/xslt.curl
@@ -1,4 +1,4 @@
-#url = "http://localhost:8081/xslt"
-url = "http://localhost:5000/xslt"
+url = "localhost/java/xslt"
+#url = "localhost/libxml/xslt"
 data = "@xslt.json"
 request = POST
diff --git a/docker-compose.yml b/docker-compose.yml
index c9e1120..eea1c0c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -10,7 +10,7 @@ services:
         container_name: xmltools-frontend
         image: xmltools-frontend
         ports:
-            - 8086:80
+            - 80:80
 
     xmltools-backend:
         build: ./Backend/tools-services