Add frontend to test broker+auth
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -7,3 +7,4 @@ dist/
 | 
				
			|||||||
.air.toml
 | 
					.air.toml
 | 
				
			||||||
tmp/
 | 
					tmp/
 | 
				
			||||||
*/*App
 | 
					*/*App
 | 
				
			||||||
 | 
					project/db-data/
 | 
				
			||||||
 | 
				
			|||||||
@ -55,7 +55,7 @@ func (app *Config) authenticate(w http.ResponseWriter, a AuthPayload) {
 | 
				
			|||||||
	// call the service
 | 
						// call the service
 | 
				
			||||||
	req, err := http.NewRequest(
 | 
						req, err := http.NewRequest(
 | 
				
			||||||
		"POST",
 | 
							"POST",
 | 
				
			||||||
		"http://authentication-service/authenticate",
 | 
							"http://authentication-service:4000/authenticate",
 | 
				
			||||||
		bytes.NewBuffer(authPayload),
 | 
							bytes.NewBuffer(authPayload),
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
				
			|||||||
@ -8,6 +8,7 @@
 | 
				
			|||||||
                <hr>
 | 
					                <hr>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <a id="brokerBtn" class="btn btn-outline-secondary" href="javascript:void(0);">Test Broker</a>
 | 
					                <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>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <div id="output" class="mt-5" style="outline: 1px solid silver; padding: 2em;">
 | 
					                <div id="output" class="mt-5" style="outline: 1px solid silver; padding: 2em;">
 | 
				
			||||||
                    <span class="text-muted">Output shows here...</span>
 | 
					                    <span class="text-muted">Output shows here...</span>
 | 
				
			||||||
@ -34,6 +35,7 @@
 | 
				
			|||||||
{{define "js"}}
 | 
					{{define "js"}}
 | 
				
			||||||
    <script>
 | 
					    <script>
 | 
				
			||||||
        let brokerBtn = document.getElementById("brokerBtn");
 | 
					        let brokerBtn = document.getElementById("brokerBtn");
 | 
				
			||||||
 | 
					        let authBrokerBtn = document.getElementById("authBrokerBtn");
 | 
				
			||||||
        let output = document.getElementById("output");
 | 
					        let output = document.getElementById("output");
 | 
				
			||||||
        let sent = document.getElementById("payload");
 | 
					        let sent = document.getElementById("payload");
 | 
				
			||||||
        let received = document.getElementById("received");
 | 
					        let received = document.getElementById("received");
 | 
				
			||||||
@ -57,5 +59,37 @@
 | 
				
			|||||||
                    output.innerHTML += "<br><br>Error: " + error;
 | 
					                    output.innerHTML += "<br><br>Error: " + error;
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        authBrokerBtn.addEventListener("click", () => {
 | 
				
			||||||
 | 
					            const payload = {
 | 
				
			||||||
 | 
					                action: "auth",
 | 
				
			||||||
 | 
					                auth: {
 | 
				
			||||||
 | 
					                    email: "admin@example.com",
 | 
				
			||||||
 | 
					                    password: "verysecret",
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            };
 | 
				
			||||||
 | 
					            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>
 | 
					    </script>
 | 
				
			||||||
{{end}}
 | 
					{{end}}
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user