From 0e2d3258ab9a2d51e18fa9ff99a3aa7a079ec8e7 Mon Sep 17 00:00:00 2001 From: lucaswadedavis Date: Mon, 19 Dec 2016 13:37:31 -0800 Subject: [PATCH 1/2] Make the server just return the image. --- server.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index ab7baa8..8672988 100644 --- a/server.js +++ b/server.js @@ -42,25 +42,24 @@ var app = express(); app.use(express.static(__dirname + '/images')); app.get('/', function(req, res) { - var fileNames = writeFoxesToDisk(200, 200, 28); - var images = fileNames.map(fileName => ''); - res.send(images.join('')); + var width = 400; + var seed = uuid(); + var canvas = composeImage(width, width, seed); + res.end(canvas.toBuffer(), 'binary'); }); app.get('/:width', function(req, res) { var width = parseInt(req.params.width) || 400; var seed = uuid(); var canvas = composeImage(width, width, seed); - var fileName = writeFoxToDisk(canvas, seed); - res.send(''); + res.end(canvas.toBuffer(), 'binary'); }); app.get('/:width/:seed', function(req, res) { var width = parseInt(req.params.width) || 400; var seed = sanitize(req.params.seed) || uuid(); var canvas = composeImage(width, width, seed); - var fileName = writeFoxToDisk(canvas, seed); - res.send(''); + res.end(canvas.toBuffer(), 'binary'); }); app.listen(process.env.PORT || 3000); From 47ff425041b19666a6e2ca04998c878fe8c582db Mon Sep 17 00:00:00 2001 From: lucaswadedavis Date: Mon, 19 Dec 2016 13:52:32 -0800 Subject: [PATCH 2/2] Make sure it returns the png header. --- server.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server.js b/server.js index 8672988..6be73ec 100644 --- a/server.js +++ b/server.js @@ -45,6 +45,7 @@ app.get('/', function(req, res) { var width = 400; var seed = uuid(); var canvas = composeImage(width, width, seed); + res.type('png'); res.end(canvas.toBuffer(), 'binary'); }); @@ -52,6 +53,7 @@ app.get('/:width', function(req, res) { var width = parseInt(req.params.width) || 400; var seed = uuid(); var canvas = composeImage(width, width, seed); + res.type('png'); res.end(canvas.toBuffer(), 'binary'); }); @@ -59,6 +61,7 @@ app.get('/:width/:seed', function(req, res) { var width = parseInt(req.params.width) || 400; var seed = sanitize(req.params.seed) || uuid(); var canvas = composeImage(width, width, seed); + res.type('png'); res.end(canvas.toBuffer(), 'binary'); });