Skip to content

Instantly share code, notes, and snippets.

@dceddia
Created June 15, 2018 02:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dceddia/b751652cab3ad1a75ead153dbed99a0a to your computer and use it in GitHub Desktop.
Save dceddia/b751652cab3ad1a75ead153dbed99a0a to your computer and use it in GitHub Desktop.
Handle GET requests
// View latest image
app.get('/', (req, res) => {
// Does this session have an image yet?
if(!latestPhoto) {
return res.status(404).send("Nothing here yet");
}
console.log('sending photo');
try {
// Send the image
var img = Buffer.from(latestPhoto, 'base64');
res.writeHead(200, {
'Content-Type': 'image/png',
'Content-Length': img.length
});
res.end(img);
} catch(e) {
// Log the error and stay alive
console.log(e);
return res.sendStatus(500);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment