-
-
Save rewdt/5d4cf7f37b4ccb516635aa026235d6f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { createServer } = require('http'); | |
createServer((req, res) => { | |
res.writeHead(200, { | |
Connection: 'Transfer-Encoding', | |
'Content-Type': 'text/html; charset=utf-8', | |
'Transfer-Encoding': 'chunked' | |
}); | |
res.write(` | |
<!doctype html> | |
<html> | |
<head><title>chunky!</title></head> | |
<body> | |
<h1>Cool Home Page!</h1> | |
`); | |
setTimeout(() => { | |
res.write('<p id="message">Still thinking...</p>'); | |
setTimeout(() => { | |
res.write(` | |
<script> | |
message.innerText = "Embarassing, sorry... here's a button to click:" | |
</script> | |
<button id="btn">click me</button> | |
<script> | |
btn.addEventListener('click', () => { | |
const hue = Math.round(Math.random() * 100) | |
document.body.style.background = "hsl("+hue+", 50%, 90%)" | |
}, false) | |
</script> | |
`); | |
setTimeout(() => { | |
res.write(` | |
<script> | |
message.innerText = "Whew! Done!" | |
btn.parentNode.removeChild(btn) | |
document.body.style.background = "" | |
</script> | |
`); | |
res.end(); | |
}, 5000); | |
}, 2000); | |
}, 2000); | |
}).listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment