You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
662 B
28 lines
662 B
import {ADDRESS} from "./constants.js";
|
|
|
|
let counter = 0;
|
|
|
|
window.onload = () => initCounter();
|
|
window.makeIncrement = () => makeIncrement();
|
|
|
|
function updateText() {
|
|
document.getElementById("counter").innerHTML = counter
|
|
}
|
|
|
|
async function makeIncrement() {
|
|
fetch(`http://${ADDRESS}/counter`, {method: 'POST'})
|
|
.then(response => { //TODO verify if it's not an error
|
|
counter++
|
|
updateText()
|
|
})
|
|
}
|
|
|
|
function initCounter() {
|
|
fetch(`http://${ADDRESS}/counter`, {method: 'GET'})
|
|
.then(response => response.json())
|
|
.then(json => {
|
|
counter = json.value
|
|
updateText()
|
|
})
|
|
}
|