Test broker from the FE
This commit is contained in:
		@ -7,6 +7,8 @@
 | 
			
		||||
                <h1 class="mt-5">Test microservices</h1>
 | 
			
		||||
                <hr>
 | 
			
		||||
 | 
			
		||||
                <a id="brokerBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Broker</a>
 | 
			
		||||
 | 
			
		||||
                <div id="output" class="mt-5" style="outline: 1px solid silver; padding: 2em;">
 | 
			
		||||
                    <span class="text-muted">Output shows here...</span>
 | 
			
		||||
                </div>
 | 
			
		||||
@ -31,6 +33,29 @@
 | 
			
		||||
 | 
			
		||||
{{define "js"}}
 | 
			
		||||
    <script>
 | 
			
		||||
        
 | 
			
		||||
        let brokerBtn = document.getElementById("brokerBtn");
 | 
			
		||||
        let output = document.getElementById("output");
 | 
			
		||||
        let sent = document.getElementById("payload");
 | 
			
		||||
        let received = document.getElementById("received");
 | 
			
		||||
 | 
			
		||||
        brokerBtn.addEventListener("click", () => {
 | 
			
		||||
            const body = {
 | 
			
		||||
                method: 'POST',
 | 
			
		||||
            }
 | 
			
		||||
            fetch("http:\/\/localhost:8080", body)
 | 
			
		||||
            .then((response) => response.json())
 | 
			
		||||
                .then((data) => {
 | 
			
		||||
                    sent.innerHTML = 'empty post request';
 | 
			
		||||
                    received.innerHTML = JSON.stringify(data, undefined, 4);
 | 
			
		||||
                    if (data.error) {
 | 
			
		||||
                        console.log(data.message);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        output.innerHTML += `<br><strong>Response from broker service</strong>: ${data.message}`;
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
                .catch((error) => {
 | 
			
		||||
                    output.innerHTML += "<br><br>Error: " + error;
 | 
			
		||||
                });
 | 
			
		||||
        });
 | 
			
		||||
    </script>
 | 
			
		||||
{{end}}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user