Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OpenWhisk web action that returns a HTML page
function main({reading}) {
var script = `
<script>
function latest_readings() {
const Http = new XMLHttpRequest();
//URL to getLatestTenReadings web action
const url='https://OPENWHISK_HOST:OPENWHISK_PORT/api/v1/web/guest/default/getLatestTenReadings';
Http.open("GET", url);
Http.send();
Http.onreadystatechange=(e)=>
{
var obj = JSON.parse(Http.responseText);
var i = 9;
document.getElementById("readings").innerHTML = "";
while (i > 4) {
document.getElementById("readings").innerHTML += obj[i].body;
document.getElementById("readings").innerHTML += "<br />";
i--;
}
}
}
latest_readings();
setInterval(latest_readings,10000);
</script>`;
return {
body: `
<html>
<style>
#readings {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border-style: solid;
border-width: 2px;
}
</style>
<body>
<h3 id="readings"></h3>
${script}
</body>
</html>`
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.