${song.title || 'Unknown'} by ${song.artist || 'Unknown'}
rating: ${song.rating}
opinion:
The /api endpoint did not respond correctly :-(
'; } mainContainer.innerHTML = html; } } document.addEventListener("DOMContentLoaded", loadHomepage); })();(function() { let mainContainer; function loadHomepage() { mainContainer = document.querySelector('#main'); const xhr = new XMLHttpRequest(); xhr.open('GET', '/api/contents?type=Song'); xhr.onreadystatechange = renderHomepage; xhr.send(null); } function renderHomepage(event) { const DONE = 4; const OK = 200; let xhr = event.currentTarget; let html = ''; if (xhr.readyState === DONE) { if (xhr.status === OK) { const songs = window.JSON.parse(xhr.responseText).data; console.log(songs); if(songs.length === 0){ html = '
There have not been any Songs added, go add some at /admin
'; } else { html = songs.map(function(song) { return `rating: ${song.rating}
The /api endpoint did not respond correctly :-(
'; } mainContainer.innerHTML = html; } } document.addEventListener("DOMContentLoaded", loadHomepage); })();