Instantly share code, notes, and snippets.

@rcdelacruz /app.js
Last active Jan 23, 2018

Embed
What would you like to do?
demo - hello world
function renderTemp(data) {
var el = document.getElementById('temperature');
el.innerHTML = data.temperature + " °C";
}
// replace with the endpoint created in your deployment.
var endpoint = 'http://localhost:3000/weather';
fetch(endpoint, { mode: 'cors' })
.then(function (resp) {
return resp.json();
})
.then(renderTemp);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>What is the temperature?</title>
<style>
h1,
h2 {
text-align: center;
font-family: sans-serif;
color: #333;
}
</style>
</head>
<body>
<h1>What is the temperature?</h1>
<h2 id='temperature'>Checking...</h2>
<script src="app.js" charset="utf-8"></script>
</body>
</html>
module.exports.getWeather = (event, context, callback) => {
const data = { temperature: 19.2 };
const response = {
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify(data)
};
callback(null, response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment