Skip to content

Instantly share code, notes, and snippets.

@dgaubert
Created September 8, 2017 17:03
Show Gist options
  • Save dgaubert/2223524e1bf3ea9f3e381ba9582e95c5 to your computer and use it in GitHub Desktop.
Save dgaubert/2223524e1bf3ea9f3e381ba9582e95c5 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<body>
<img id="200-body-tile" src="http://localhost:3000/200-body-tile" width="256" height="256">
<img id="429-body-tile" src="http://localhost:3000/429-body-tile" width="256" height="256">
<img id="200-body-no-renderable" src="http://localhost:3000/200-body-no-renderable" width="256" height="256">
<img id="429-body-no-renderable" src="http://localhost:3000/429-body-no-renderable" width="256" height="256">
<script type="text/javascript">
document.getElementById("200-body-tile").addEventListener('load', function () {
console.log('200-body-tile: load')
});
document.getElementById("200-body-tile").addEventListener('error', function () {
console.log('200-body-tile: error')
});
document.getElementById("429-body-tile").addEventListener('load', function () {
console.log('429-body-tile: load')
});
document.getElementById("429-body-tile").addEventListener('error', function () {
console.log('429-body-tile: error')
});
document.getElementById("200-body-no-renderable").addEventListener('load', function () {
console.log('200-body-no-renderable: load')
});
document.getElementById("200-body-no-renderable").addEventListener('error', function () {
console.log('200-body-no-renderable: error')
});
document.getElementById("429-body-no-renderable").addEventListener('load', function () {
console.log('429-body-no-renderable: load')
});
document.getElementById("429-body-no-renderable").addEventListener('error', function () {
console.log('429-body-no-renderable: error')
});
</script>
</body>
</html>
const fs = require('fs')
const http = require('http');
const tile = fs.readFileSync(`${__dirname}/tile.png`, { encoding: null });
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.setHeader('Content-Type', 'image/png')
switch (req.url) {
case '/200-body-tile':
res.statusCode = 200
res.end(tile, 'binary')
break;
case '/429-body-tile':
res.statusCode = 429
res.end(tile, 'binary')
break;
case '/200-body-no-renderable':
res.statusCode = 200
res.end('')
break;
case '/429-body-no-renderable':
res.statusCode = 429
res.end('')
break;
default:
res.statusCode = 404
res.end()
break;
}
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment