Created
June 15, 2018 02:03
-
-
Save dceddia/b751652cab3ad1a75ead153dbed99a0a to your computer and use it in GitHub Desktop.
Handle GET requests
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
// 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