Add frontend to test broker+auth
This commit is contained in:
parent
9edb249430
commit
b8417c47b9
1
.gitignore
vendored
1
.gitignore
vendored
@ -7,3 +7,4 @@ dist/
|
||||
.air.toml
|
||||
tmp/
|
||||
*/*App
|
||||
project/db-data/
|
||||
|
@ -55,7 +55,7 @@ func (app *Config) authenticate(w http.ResponseWriter, a AuthPayload) {
|
||||
// call the service
|
||||
req, err := http.NewRequest(
|
||||
"POST",
|
||||
"http://authentication-service/authenticate",
|
||||
"http://authentication-service:4000/authenticate",
|
||||
bytes.NewBuffer(authPayload),
|
||||
)
|
||||
if err != nil {
|
||||
|
@ -8,6 +8,7 @@
|
||||
<hr>
|
||||
|
||||
<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;">
|
||||
<span class="text-muted">Output shows here...</span>
|
||||
@ -34,6 +35,7 @@
|
||||
{{define "js"}}
|
||||
<script>
|
||||
let brokerBtn = document.getElementById("brokerBtn");
|
||||
let authBrokerBtn = document.getElementById("authBrokerBtn");
|
||||
let output = document.getElementById("output");
|
||||
let sent = document.getElementById("payload");
|
||||
let received = document.getElementById("received");
|
||||
@ -57,5 +59,37 @@
|
||||
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>
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user