debug and make mail work
This commit is contained in:
		@ -10,6 +10,7 @@
 | 
			
		||||
                <a id="brokerBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Broker</a>
 | 
			
		||||
                <a id="authBrokerBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Auth</a>
 | 
			
		||||
                <a id="logBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Log</a>
 | 
			
		||||
                <a id="mailBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Mail</a>
 | 
			
		||||
 | 
			
		||||
                <div id="output" class="mt-5" style="outline: 1px solid silver; padding: 2em;">
 | 
			
		||||
                    <span class="text-muted">Output shows here...</span>
 | 
			
		||||
@ -37,7 +38,7 @@
 | 
			
		||||
    <script>
 | 
			
		||||
        let brokerBtn = document.getElementById("brokerBtn");
 | 
			
		||||
        let authBrokerBtn = document.getElementById("authBrokerBtn");
 | 
			
		||||
        let logBtn = document.getElementById("logBtn");
 | 
			
		||||
        let mailBtn = document.getElementById("mailBtn");
 | 
			
		||||
        let output = document.getElementById("output");
 | 
			
		||||
        let sent = document.getElementById("payload");
 | 
			
		||||
        let received = document.getElementById("received");
 | 
			
		||||
@ -126,5 +127,39 @@
 | 
			
		||||
                });
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        mailBtn.addEventListener("click", () => {
 | 
			
		||||
            const payload = {
 | 
			
		||||
                action: "mail",
 | 
			
		||||
                mail: {
 | 
			
		||||
                    from: "admin@example.com",
 | 
			
		||||
                    to: "me@here.com",
 | 
			
		||||
                    subject: "This is not a phishing mail",
 | 
			
		||||
                    content: "Send me money now!",
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
            const headers = new Headers();
 | 
			
		||||
            headers.append("Content-Type", "application/json");
 | 
			
		||||
            const body = {
 | 
			
		||||
                method: 'POST',
 | 
			
		||||
                body: JSON.stringify(payload),
 | 
			
		||||
                headers: headers,
 | 
			
		||||
            }
 | 
			
		||||
            fetch("http:\/\/localhost:8080/handle", body)
 | 
			
		||||
            .then((response) => response.json())
 | 
			
		||||
                .then((data) => {
 | 
			
		||||
                    sent.innerHTML = JSON.stringify(payload, undefined, 4);
 | 
			
		||||
                    received.innerHTML = JSON.stringify(data, undefined, 4);
 | 
			
		||||
                    if (data.error) {
 | 
			
		||||
                        console.log(data.message);
 | 
			
		||||
                        output.innerHTML += `<br><strong>Error:</strong>: ${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